SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast stevem01's Avatar
    Join Date
    Apr 2001
    Location
    Modesto, CA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replacing a space with a plus sign - PHP

    I'm integrating searchfeed.com into a clients site and I ran into a problem...

    Appearently searchfeed.com only offers the searchbox form that redirects to their site... so to keep visitors at the site I created my own form and posted the search query to my page: searchresult.php?query=search+term

    Since searchfeed.com displays their affiliate searches via embedded javascript with the keyword hard coded into it, I just put the php code <?=$query?> where the search term should be and it worked fine... except when someone uses more than one word to search (i.e. web hosting service)...

    sfeed says the query has to be url-encoded, I've tweaked with it all night ... and morning now and can't get it to work. Just wanted to see if there was an easy way in php to just take a text string and URL-encode it ... Like change 'web hosting search' to 'web+hosting+search'

    I've been up all night so if I'm not being clear enough let me know..

    Thanks in advance... ANY help would be great.

    -Steve

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query = urlencode($query);


  3. #3
    SitePoint Enthusiast stevem01's Avatar
    Join Date
    Apr 2001
    Location
    Modesto, CA
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks TWT!

    I went to php.net and looked up some replacement functions and ended up copying some user supplied addition to the eregi_replace func. that looked like it would work...

    $clean = trim(eregi_replace("[[:space:]]", "+" , $query));

    I knew it was probably complete overkill and out of context...but hey, it worked in a jam...

    I'll definately be using your suggestion though... if it was a snake it woulda' bit me...

    I can't wait until WROXs Pro PHP4 comes out in june... I've been holding out and hitting the tutorials in the meanwhile...

    Thanks again for your help! I appreciate it.


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
  •