codrgii Posted April 30, 2011 Share Posted April 30, 2011 How in php using the preg_replace php function can i allow only the basic english a-z letters, numbers 0-9 and unicode code letters and remove anything else? Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/ Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 preg_replace('#[^A-Za-z0-9]#i', $replacement, $str_to_search); Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208664 Share on other sites More sharing options...
silkfire Posted April 30, 2011 Share Posted April 30, 2011 Wrong fugix that will drop all European letters like åäöóè etc. I suggest you analyze what it is the user inputs and make a list of the most common characters and allow them only. Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208700 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 yes you are right silk...i missed that he wants to keep all unicode letters as well....my mistake...codrgii...you could make it work with preg_replace...but it would take a while to gather all of the letters that you want to keep.you might want to try what silk suggests and take the most used unicode letters to add to your preg_replace filter Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208702 Share on other sites More sharing options...
codrgii Posted April 30, 2011 Author Share Posted April 30, 2011 take the most used unicode letters to add to your preg_replace filter I new to php, so i don't quite know how to do that yet... I tried the example you shown but it dropped the unicode letters. Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208736 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 what is the range of unicode letters that you would like to keep...if you are not sure of the range....click here Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208741 Share on other sites More sharing options...
codrgii Posted April 30, 2011 Author Share Posted April 30, 2011 It is Latin A and B. Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208761 Share on other sites More sharing options...
fugix Posted April 30, 2011 Share Posted April 30, 2011 then for your pattern to use in preg_replace try $pattern ='/[^\x{0100}-\x{024F}]+/u'; to remove the other unicode characters but keep the ones that you stated Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208764 Share on other sites More sharing options...
codrgii Posted April 30, 2011 Author Share Posted April 30, 2011 Thanks for your help, but it still dosen't work, i don't know if i put this wrong, so i'll lay it out for you to see. $unicode = "pízza1234"; preg_replace('/[^\x{0100}-\x{024F}]+/u', '', $unicode); echo $unicode; doing that returns nothing at all, it dosen't even show the basic a-z, 0-9. Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1208780 Share on other sites More sharing options...
codrgii Posted May 1, 2011 Author Share Posted May 1, 2011 - Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1209077 Share on other sites More sharing options...
fugix Posted May 1, 2011 Share Posted May 1, 2011 http://us2.php.net/manual/en/function.preg-replace.php Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1209092 Share on other sites More sharing options...
codrgii Posted May 1, 2011 Author Share Posted May 1, 2011 It's just too easy to do that, i'm aware of the function just not so with some unicode latin letters hence this topic, every thing you have said thus far has not worked, if you don't know yourself then please don't act like you do. I appreciate your effort but theres irony in your last post. Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1209124 Share on other sites More sharing options...
fugix Posted May 1, 2011 Share Posted May 1, 2011 I did that becauseou bumped your thread which is against forum rules. And in the link that I posted talks about your issue in one if the comments if you would take the time to read that far down Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1209128 Share on other sites More sharing options...
codrgii Posted May 1, 2011 Author Share Posted May 1, 2011 I did that becauseou bumped your thread which is against forum rules. They have mods, why do you care? if the comments if you would take the time to read that far down Thanks for pointing that out, i found it but not what i originally asked for. Does anyone know how to use latin a-b unicode with preg_replace? Quote Link to comment https://forums.phpfreaks.com/topic/235193-unicode-letters/#findComment-1209141 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.