Jump to content

[SOLVED] URI problems


xenophobia

Recommended Posts

so let say I got a php filename: my.php which receive a request of myvar:

my.php?myvar=hello world

So $_REQUEST['myvar'] will get the data.

 

how if I wan my 'myvar' contained an ampersand? Which looks like:

my.php?myvar=hello&world

So it became two request:

$_REQUEsT['myvar'] and $_REQUEST['word']

 

Any solutions?

Link to comment
Share on other sites

If you are constructing the URL in php, do it like this:

 

$url = 'my.php?myvar=' . urlencode($myvar);

 

When browsers submit form data, they do this process automatically, so it's only necessary for when you construct your own urls.  When you receive the data in $_REQUEST['myvar'], you must use urldecode() to convert it back.

Link to comment
Share on other sites

Actually Im using Ajax to send the url. So there will be no any function like urlencode in javascript. :'(

 

But anyway thanks for that function and i discovered that '&' is equals to %26. So i just replace the url string from & -> %26. And is work. Thanks anyway.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.