I want to do a function for converting some strange characters into US characters as below: - if the character is one of: "ó, ò, á», õ, á», ô, ố, ồ, ổ, á»—, á»™, Æ¡, á»›, á», ở, ỡ, ợ", then the function will change to "o". - if the character is one of: "á, à , ả, ã, ạ, ă, ắ, ằ, ẳ, ẵ, ặ, â, ấ, ầ, ẩ, ẫ, áº", then the function will change to "a". - if the character is one of: "é, è, ẻ, ẽ, ẹ, ê, ế, á», ể, á»…, ệ", then the function will change to "e". - if the character is one of: "ú, ù, á»§, Å©, ụ, ư, ứ, ừ, á», ữ, á»±", then the function will change to "u". - if the character is one of: "Ã, ì, ỉ, Ä©, ị", then the function will change to "i". I tried to write this function, but the input is encoded in UTF-8 unicode, if I use HTML codes of these characters, it cannot convert. Thank you for your help.
Hi You can do it like this <? $what_to_replace = array("/ó/","/á/","/é/"); $replace_with = array("o","a","e"); print preg_replace($what_to_replace, $replace_with, "ó123é456á"); // Out put will be like this o123e456a ?> PHP: Thanks
I tried this method, but these characters cannot be typed in textfield of notepad (editor for my scripts)
Thank bro! To have these characters I must use an external tool for typing. It doesn't work well on Linux, and I don't have a Dreamwaver, what should I do?
Hi, Can you tell me one more thing , those values 'ó' i mean this kind of characters are stored in database ? if yes then you can also remove them by sql queries. thanks
Thank you for your reply. I'm writing a submit form for a post of contents, and want to rewrite URLs, for example, the user will fill out the TITLE of the post in these chararters, the form will assign an URL rewriting automatically, but in US ASCII characters.
hey, if you are unable to use the actual character, try using there ascii code then use chr() to generate the character in a str_replace method...I can help if you pm me.
Hi, thank for you guide. But the method using chr() is a bit inapplicable. For example, to type "ô" in the form, the user must type "o" two times or "o" with number 5. Is it a hard problem to be resolved?
Part of your problem is, some of the symbols are unicode, PHP doesn't actively support unicode yet...Well php 6 does but not 4 or 5. I think you can replace some of the characters...but not sure about the rest.
Eureka! I resolved it ! As following, - In the submit form, I use encode charset UTF-8 - step 2: $src = urlencode($src); $src = preg_replace('/\%/', '', $src); $src = preg_replace('/C3A1/', 'a', $src); // "á" value has been changed to a $src = preg_replace('/C3A0/', 'a', $src); // "à " value has been changed to a $src = preg_replace('/E1BAA3/', 'a', $src); // "ả" value has been changed to a $src = preg_replace('/C3A3/', 'a', $src); // "ã" value has been changed to a $src = preg_replace('/E1BAA1/', 'a', $src); // "ạ" value has been changed to a Code (php): - step 3: By the way, thank all pro bros.