Results 1 to 3 of 3

Thread: Strip/replace url part?

  1. #1
    Join Date
    May 2010
    Posts
    30
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Strip/replace url part?

    Hello,

    I have a url from my site A that I want to load into a href= tag of my site B

    url from site A= http://domain.com/5234566/site A.php
    I want only the 5234566 to be load into my href on site B

    <A HREF="site B.php?id=5234566">SITE B</A>
    Is this possible?

    Thank you in advance!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You can use string functions like strpos() and substr(), or you could use regex, which is more complicated but more powerful.

    The main question is how exactly you can determine where that string will be in the URL. It may seem simple for you to find it, but you will need to give the computer very specific instructions. Is it always the first element after the domain name? Does it always start with 5? Does it only contain numbers? Maybe the only way you can recognize it is that it will be the only string in it that is exactly 7 numbers long, without any other characters. But whatever you do, make sure it isn't possible that there are any variations or duplicates or you might get unexpected results.

    A way to determine how to approach this sort of problem is this: how consistent is the format? If you get a URL that looks almost exactly like that every time, it's easy. If there are many ways it can differ, it's a lot more complex.

    If you have trouble, you can post some examples of what the URLs will look like and please include all possible variations (not all possible URLs, but just the format variations).

    If the format is relatively similar all the time, you could try this as an easy method:
    http://php.net/manual/en/function.parse-url.php
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2007
    Posts
    68
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Use php explode then grab the fourth part of the array (I think it's the fourth, some trial and error will find out):

    http://php.net/manual/en/function.explode.php


    If that's what you mean. Maybe expand a bit more on what exactly you want.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •