1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to get text from url string?

Discussion in 'PHP' started by pizzapizza, Sep 13, 2013.

  1. #1
    Hi,
    I have some following urls:
    Screen Shot 2013-09-13 at 3.39.18 PM.png
    SEMrush
    So, how to get the red text (value of MERCHANTID) in those urls?
    Thanks in advance.
     
    Solved! View solution.
    pizzapizza, Sep 13, 2013 IP
    SEMrush
  2. #2
    Assuming $url is the URL, $vars['MERCHANTID'] will be what you want...
    parse_str(parse_url($url, PHP_URL_QUERY), $vars);
    echo $vars['MERCHANTID'];
    PHP:
     
    digitalpoint, Sep 13, 2013 IP
  3. pizzapizza

    pizzapizza Active Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    The code is working perfectly! Thanks bros.
     
    pizzapizza, Sep 13, 2013 IP
  4. Wickedd

    Wickedd Greenhorn

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #4
    Actually the code he wrote is a way but i think not the best.
    Notice the URL contains a GET element wich u can retrieve using the
    $_GET[''];
    Code (markup):
    variable.

    I think i'd rather go for this:
    
    if(isset($_GET['MERCHANTID'])){
    $merchid = $_GET['MERCHANTID'];
    }
    
    Code (markup):
    Or you could create a for each loop on the GET array and place it in a new one check if the merchantid value exists.

    -Wickedd
     
    Wickedd, Sep 13, 2013 IP
  5. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,300
    Likes Received:
    2,604
    Best Answers:
    461
    Trophy Points:
    710
    Digital Goods:
    29
    #5
    He never said if the URL was a URL the script was running in though... $_GET might not have the info.
     
    digitalpoint, Sep 13, 2013 IP
    Basti likes this.