Forum Moderators: coopster

Message Too Old, No Replies

urlencode

Need a little guidance.

         

mack

1:01 am on Nov 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



<?php
include "ht^p://www.domain.com/dir/include.cgi?query=$qry
?>

The above code is a snippet from a page I am working on. It is designed to dynamicaly include another page based on qry value.

It works great when the qry value is one word. But if there is more than one word it causes php errors.

I assume I need to use urlencode. Does anyone have any idea how I could modify the code to acomodate this?

Thanks in advance.

Mack.

coopster

2:13 am on Nov 5, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



See if this works, mack:
<?php 
include "ht^p://www.domain.com/dir/include.cgi?query=".urlencode($qry);
?>


If you were trying to urlencode the entire string, like this:
urlencode("http://www.domain.com/dir/include.cgi?query=$qry"); 

it wouldn't work. Let's say the $qry variable had the good old value of 'Hello World'. It would end up something like this:
http%3A%2F%2Fwww.domain.com%2Fdir%2Finclude.cgi%3Fquery%3DHello+World 

whereas the output of the example I show would give you:
http://www.domain.com/dir/include.cgi?query=Hello+World 

Notice the difference? Hope this helps -- coopster