Jump to content

avoid special character on url


robert_gsfame

Recommended Posts

How can i avoid special character to be written on url..

let say i have

 

mypage.php?name=James+Barnwell

 

then when i put special character like %?()* n i will get an error...i know that this is very dangerous but i dont have any idea on how to avoid that

 

i try to use str_replace but not working...

 

$string=$_GET['value'];

$replacethis=array('\%','\?','\*');

$replaceby=array('','','');

$string1=str_replace($replacethis,$replaceby,$string);

 

 

 

 

Link to comment
Share on other sites

You can undo urlencode with its brother function urldecode. When you're passing the names in the url you'll use urlencode, eg

 

$name = 'Jim Carey';
echo '<a href="name.php?name='.urlencode($name).'">Send Name</a>';

 

When you reftrieve the name from the url you'll use urldecode,

if(isset($_GET['name']))
    echo urldecode($_GET['name']);

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.