Welcome to WebmasterWorld Guest from 54.234.153.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Encoding a URL

url encode

     

immatt

2:32 pm on Sep 15, 2009 (gmt 0)

5+ Year Member



I am trying to make an input that when submitted it will search google. My script looks like this

$input = 'url encoding';
$gsearch = urlencode($input);

print '<a href="http://www.google.com/#hl=en&q='.$gsearch.'">Google Search</a>';

The link will end up being:

[google.com...]

(I am testing it on my computer)

Would I have to us preg_replace to take out the "http://localhost/" or is there some other way to do that?

rainborick

4:31 pm on Sep 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're on the right track. I would suggest that you do your best to encode any space characters in the search string as '+' instead of '%20' to make the request look more natural to Google. If Google starts to see your code as making automated queries, they will block the requests.

StupidScript

10:50 pm on Sep 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have never seen urlencode add the protocol and host to the data it is encoding. urlencode simply makes whatever is passed to it "friendly" for use, by replacing spacebars with + signs, etc.

If you need to strip out the host name, use $_SERVER['REQUEST_URI'] [us2.php.net].

 

Featured Threads

Hot Threads This Week

Hot Threads This Month