mindsoul Posted March 20, 2007 Share Posted March 20, 2007 i have developed a website in 5 languages and i got to build a content management system to control the content. i wanted to build a function that replace special characters with ascii code to be sure that in my db everything is clean and i don't want a surprise when the text is publish this is a a part of the list of char i need to replace, i used various function to make this but neither one was ok for the 5 language i use(en/de/it/hu/ro): [ è ]_______________è............................. e grave// [ é ]_______________é.............................e acute// [ Á ]_______________Á.............................A acute// [ À ]_______________À.............................A grave// [ á ]_______________á.............................a acute// [ à ]_______________à.............................a grave// [ ì ]_______________ì.............................i grave// [ í ]_______________í.............................i acute// [ ò ]_______________ò.............................o grave// [ ó ]_______________ó.............................o acute// [ ő ]_______________ő.............................o maghiar// [ Ó ]_______________Ó.............................O acute// [ ù ]_______________ù.............................u grave// [ ú ]_______________ú.............................u acute// [ ű ]_______________ű.............................u maghiar// [ ü ]_______________ü.............................u uml// [ ë ]_______________ë.............................e uml// [ ö ]_______________ö.............................o uml// [ Ö ]_______________Ö.............................O uml// [ ü ]_______________ü.............................u uml// [ Ü ]_______________Ü.............................U uml// [ ä ]_______________ä.............................a uml// [ Ä ]_______________Ä.............................A uml// [ ß ]_______________ß.............................ss zed// [ - ]_______________−.............................minus sign// [ ~ ]_______________∼.............................tilde sign// [ \ ]_______________".............................quot, quotation mark// [ \"]_______________".............................quot, quotation mark// [ < ]_______________<............................. less than// [ > ]_______________>............................. greater than// [ ´ ],_______________´............................. acute// [ ' ]_______________´............................. acute// Do somebody know a method to solve this without problems? Thanks in advance. It's quite a wile I'm searching the answer to this problem It was easy with 3 languages it/de/en but when i added the east european languages(hu/ro) all became a real headache. Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/ Share on other sites More sharing options...
Baving Posted March 20, 2007 Share Posted March 20, 2007 For one character you can use the ord function to return the ASCII value. The code below would echo 65 for example. <? $value = 'A'; echo ord($value); ?> www.php.net/ord Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-211356 Share on other sites More sharing options...
genericnumber1 Posted March 20, 2007 Share Posted March 20, 2007 I'm not sure if http://www.php.net/htmlentities htmlentities() will do it or not, I've never had to try it. Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-211393 Share on other sites More sharing options...
mindsoul Posted March 20, 2007 Author Share Posted March 20, 2007 i try this function function htmlnumericentities($str){ return preg_replace('/[^!-%\x27-;=?-~ ]/e', '"&#".ord("$0").chr(59)', $str); } function numericentitieshtml($str){ return utf8_encode(preg_replace('/&#(\d+);/e', 'chr(str_replace(";","",str_replace("&#","","$0")))', $str)); } but still doesn't recognize the char î î Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-211427 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 You could place them into the database as the code, and when retrieving them convert them back. IE: <?php $charArr = array("char" => "î"); $input = "char and than there was char"; foreach ($charArr as $char => $val) { $input = str_replace($char, $val, $input); } // place input into DB // now grab input from DB $output = "î and than there was î"; foreach ($charArr as $char => $val) { $output = str_replace($val, $char, $input); } print $output; ?> I may be missing the point, but I think it would work? Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-211714 Share on other sites More sharing options...
mindsoul Posted March 21, 2007 Author Share Posted March 21, 2007 the problem is that i already have all the chars in db converted to ascii. so i want something that convert every special caracters(letters) to ascii &#...; i've made this function that replace only what i need : function formatare($text){ $text=str_replace("è","è",$text);//e grave// $text=str_replace('é','é',$text);//e acute// $text=str_replace('Á','Á',$text);//A acute// $text=str_replace('À','À',$text);//A grave// $text=str_replace('á','á',$text);//a acute// $text=str_replace('à','à',$text);//a grave// $text=str_replace('ì','ì',$text);//i grave// $text=str_replace('í','í',$text);//i acute// $text=str_replace('ò','ò',$text);//o grave// $text=str_replace('ó','ó',$text);//o acute// $text=str_replace('Ó','Ó',$text);//O acute// $text=str_replace('ù','ù',$text);//u grave// $text=str_replace('ú','ú',$text);//u acute// $text=str_replace('ë','ë',$text);//e uml// $text=str_replace('ö','ö',$text);//o uml// $text=str_replace('Ö','Ö',$text);//O uml// $text=str_replace('ü','ü',$text);//u uml// $text=str_replace('Ü','Ü',$text);//U uml// $text=str_replace('ä','ä',$text);//a uml// $text=str_replace('Ä','Ä',$text);//A uml// $text=str_replace('ß','ß',$text);//ss zed// //$text=str_replace('-','−',$text);//minus sign// $text=str_replace('~','∼',$text);//tilde sign// $text=str_replace("´","´",$text);// acute// $text=str_replace("'","´",$text);// acute// return $text; } // but still there are some chars like ő ; that can not be seen so if i put in my function this char like : $text=str_replace("ő'","ő",$text);// acute// this char is not seen by my function and will not replaced but replace all "a" chars and that is something that i do not want. I thought that the problems is may declaration of the charset <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8"/> i try with different declarations like east-european iso-8859-2 but nothing i don't really understand maybe php don't recognize this type of chars. Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-212151 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 Can you provide an example of what is in the database, a short except with some special chars and than what you want it to look like? Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-212159 Share on other sites More sharing options...
mindsoul Posted March 21, 2007 Author Share Posted March 21, 2007 this is the db text in hungarian: Show fesztivál szilveszter éjszakán Jesolóban Rendezvények Jesolóban Szilveszter éjszakán zenés, varázslatos mix várja a látogatókat Jesolóban, a Show−fesztivál alkalmából, a rendezvényt Jesoló város polgármesteri hivatala szponzorálja és a Rádió Birikina, valamint a Rádió Bella&Monella szervezése. A fesztivál december 2006/12/31−én 22,00 órakor kezdődik a Milanó−i piac környékén Jesoló Lidóban.A belépés díjtalan. and this is the output: Show fesztivál szilveszter éjszakán Jesolóban Rendezvények Jesolóban Szilveszter éjszakán zenés, varázslatos mix várja a látogatókat Jesolóban, a Show−fesztivál alkalmából, a rendezvényt Jesoló város polgármesteri hivatala szponzorálja és a Rádió Birikina, valamint a Rádió Bella&Monella szervezése. A fesztivál december 2006/12/31−én 22,00 órakor kezdődik a Milanó−i piac környékén Jesoló Lidóban.A belépés díjtalan. this is the db text in italian: La notte di San Silvestro a Jesolo si festeggia con la musica e la magia del Festival Show, manifestazione promossa dal Comune di Jesolo ed organizzata da Radio Birikina e Radio Bella & Monella. L´evento si terrà dalle ore 22.00 in Piazza Mazzini sabato 31 dicembre. L´ingresso sarà gratuito. La notte di San Silvestro a Jesolo si festeggia con la musica e la magia del Festival Show, manifestazione promossa dal Comune di Jesolo ed organizzata da Radio Birikina e Radio Bella & Monella. L´evento si terrà dalle ore 22.00 in Piazza Mazzini sabato 31 dicembre. L´ingresso sarà gratuito. all this texts are available in 5 languages. to be sure i convert all the chars to ascii. as you can see this form here in the forum just do the job of converting the chars, i want something similar. in some pages i have html so i don't need something to convert html to ascii, but only the chars(letters), here i see that the chars set is iso-8859-1 called also latin1 Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-212170 Share on other sites More sharing options...
mindsoul Posted March 21, 2007 Author Share Posted March 21, 2007 the text i put it up there is shown like this <div class="quote">Show fesztivál szilveszter éjszakán Jesolóban Rendezvények Jesolóban Szilveszter éjszakán zenés, varázslatos mix várja a látogatókat Jesolóban, a Show−fesztivál alkalmából, a rendezvényt Jesoló város polgármesteri hivatala szponzorálja és a Rádió Birikina, valamint a Rádió Bella&Monella szervezése. A fesztivál december 2006/12/31−én 22,00 órakor kezdődik a Milanó−i piac környékén Jesoló Lidóban.A belépés díjtalan.</div> as you can see they replace only few chars when i submit strange text, they are changing only this chars ő ;that are not in iso-8859-1 charset but in iso-8859-2 so that's why they are replacing with ascii. Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-212181 Share on other sites More sharing options...
mindsoul Posted March 23, 2007 Author Share Posted March 23, 2007 so nobody know how to do this? Quote Link to comment https://forums.phpfreaks.com/topic/43520-site-in-5-languages-special-entities-convert-to-asci-problem/#findComment-213725 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.