robert_gsfame Posted July 11, 2010 Share Posted July 11, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/207412-avoid-special-character-on-url/ Share on other sites More sharing options...
trq Posted July 11, 2010 Share Posted July 11, 2010 urlencode. Quote Link to comment https://forums.phpfreaks.com/topic/207412-avoid-special-character-on-url/#findComment-1084383 Share on other sites More sharing options...
robert_gsfame Posted July 11, 2010 Author Share Posted July 11, 2010 when i use urlencode() assume "Jim Carey", then i will have trouble with the query I will have $query=mysql_query("SELECT * FROM table1 WHERE actor_name='Jim+Carey'"); instead of $query=mysql_query("SELECT * FROM table1 WHERE actor_name='Jim Carey'"); ??? Quote Link to comment https://forums.phpfreaks.com/topic/207412-avoid-special-character-on-url/#findComment-1084438 Share on other sites More sharing options...
robert_gsfame Posted July 11, 2010 Author Share Posted July 11, 2010 okay..i got it! although i rather choose to use str_replace and replace or special character which is not needed... anyway thx Quote Link to comment https://forums.phpfreaks.com/topic/207412-avoid-special-character-on-url/#findComment-1084444 Share on other sites More sharing options...
Pikachu2000 Posted July 11, 2010 Share Posted July 11, 2010 Did you try it without using strreplace()? The superglobals $_GET and $_REQUEST are already decoded. Quote Link to comment https://forums.phpfreaks.com/topic/207412-avoid-special-character-on-url/#findComment-1084451 Share on other sites More sharing options...
wildteen88 Posted July 11, 2010 Share Posted July 11, 2010 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']); Quote Link to comment https://forums.phpfreaks.com/topic/207412-avoid-special-character-on-url/#findComment-1084452 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.