Rommeo Posted December 12, 2009 Share Posted December 12, 2009 I m taking a text from user and I m using it as a link. like ; // My function $targetChars=array('<', '>', '\\'); $text=str_replace($targetChars, "+", $text); user entered : "my name is>Rommeo" link : www.mysite.com/my+name+is+Rommeo I need to remove the special chars. But today I have noticed that user can enter a char in his/her language or something like a comma, dot etc. So simply, instead of removing special chars from the text that user entered, I just want to take letters that are in english alphabet, and when there is a whitespace I want to put there "+" sign. Cause otherwise, since I do not know what user will enter, It wont be usefull to write all chars and special chars into targetChars array that are not in english alphabet. So can anyone tell me a way to do this ? Is there any special function for this purpose ? Thanx in advance. Quote Link to comment https://forums.phpfreaks.com/topic/184905-making-links-removing-special-chars/ Share on other sites More sharing options...
ngreenwood6 Posted December 12, 2009 Share Posted December 12, 2009 i think that you are looking for url encode: $name = urlencode('my name is>romeo'); echo $name; this will return my+name+is%3Eromeo automatically does the processing for you. Quote Link to comment https://forums.phpfreaks.com/topic/184905-making-links-removing-special-chars/#findComment-976115 Share on other sites More sharing options...
Daniel0 Posted December 12, 2009 Share Posted December 12, 2009 Specifically, what characters do you allow? It's easier making a whitelist than a blacklist. If you only want alphanumeric chars you can do $str = urlencode(preg_replace('#[^a-z0-9]#i', '', $str)); Quote Link to comment https://forums.phpfreaks.com/topic/184905-making-links-removing-special-chars/#findComment-976116 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.