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.

Inserting a portion of the URL in a page

Discussion in 'HTML & Website Design' started by dlm, Jul 3, 2009.

  1. #1
    Hi all,

    Not sure if this is possible with just HTML, but I assume it isn't that difficult.

    If I sent people to a link like this: www.mydomain.com/?searchterm
    Is there anyway I could insert "searchterm" in my page easily? That way I could make a page header or something say buy "searchterm" here or whatever.

    Obviously the page would need to update for each visitor automatically based on the URL (the part after the ?) he arrived using.

    Can anyone point me in the right direction?

    Thanks.
     
    dlm, Jul 3, 2009 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Not in HTML, but if you make it a php page, just throw this in where ever you want searchterm to print.
    <?php
    foreach($_GET as $key => $value){
         echo $key;
    }
    ?>
    PHP:
    There's probably an easier way, but that works fine for me at least.

    JavaScript can probably do it as well.
     
    crath, Jul 3, 2009 IP
    dlm likes this.
  3. wierdo

    wierdo Well-Known Member

    Messages:
    1,646
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Your domain would have to be something like yourdomain.com/index.php?search=whatever if you're using PHP.
     
    wierdo, Jul 3, 2009 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    Not if he uses what I just posted...
     
    crath, Jul 3, 2009 IP
  5. dlm

    dlm Peon

    Messages:
    3,123
    Likes Received:
    86
    Best Answers:
    0
    Trophy Points:
    0
    #5
    + rep added - that works like a charm - thanks!

    One more quick thing, when I use /?search%20term
    the result on the page is search_term

    Any way to make a space show up instead of the line?
     
    dlm, Jul 4, 2009 IP
  6. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #6
    <?php
    foreach($_GET as $key => $value){
         $key = str_replace('_',' ',$key);
         echo $key;
    }
    ?>
    
    PHP:
    There's probably a nicer way to do it though.
    I thought urldecode would do it, but I just tried it and it doesn't work well with $_GET.
     
    Kerosene, Jul 4, 2009 IP
  7. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #7
    What does /?search+term spit out?
     
    crath, Jul 4, 2009 IP
  8. dlm

    dlm Peon

    Messages:
    3,123
    Likes Received:
    86
    Best Answers:
    0
    Trophy Points:
    0
    #8
    underline (_) as well
     
    dlm, Jul 4, 2009 IP
  9. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #9
    I suggest using + instead of %20, looks nicer :)

    <?php
    foreach($_GET as $key => $value){
         echo str_replace("+"," ",$key);
    }
    ?>
    Code (markup):
     
    crath, Jul 4, 2009 IP