Search code examples
phpajaxurlvariables

How to send URL (with vars in it) as a single var?


I have a url string like this:

http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g

I need to send this url from ajax to a php script as a single string variable.

I am having trouble though because it keeps getting split into several vars because of the vars in the url string itself. Make sense? How can I send this as a single string??

Thanks!!!


Solution

  • You need to encode it.

    In PHP: urlencode()

    $str = urlencode('http://....');
    

    In Javascript: encodeURIComponent

    str = encodeURIComponent('http://...');