williamZanelli Posted August 25, 2010 Share Posted August 25, 2010 Hi guys, I'm parsing some data from a Spanish source, it has spanish chars inside CDATA brackets, chars like "é" - when I view source, the character ("é") is dispalyed as "í" - I've tried numerous ways or replacing this character.. with some other letter and it doesnt seem to work. Here's some code function handleSpanishCharacters($input) { $translate['í'] = "a";// $translate['á'] = "a"; $search = array_keys($translate); $replace = array_values($translate); return str_replace($search,$replace,$input); } What am I doing wrong? Does someone have a working solution that I can use? Any ideas on how I could fix this darrn prob? Cheers Will Link to comment https://forums.phpfreaks.com/topic/211738-removingreplace-spanish-chars/ Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 Heya i know nothing about spanish, but i just read a nice post By alkimuz (Today at 10:23:03 PM by Alkimuz) on this forum and I think it can help you with your problem too. He used it for BB-code. But since i stil have to learn I applied what he did on your case, hope it works. The idea is that user can input any data (ofc sanitize htmlspecialcaracters(),) But ones it is retrieved from the database right before its show its gonna be sanitized to what you want. So a í will be an a. <?php $data= str_replace("í", "a", $data); $data= str_replace("á", "a", $data); //etc.. //and after that, you can place the data echo $data; ?> original post: http://www.phpfreaks.com/forums/index.php/topic,308342.0.html Link to comment https://forums.phpfreaks.com/topic/211738-removingreplace-spanish-chars/#findComment-1103793 Share on other sites More sharing options...
Alkimuz Posted August 26, 2010 Share Posted August 26, 2010 hey Wil, what i dont understand is that for example é is changed into í as the right code would be é (http://www.w3schools.com/tags/ref_entities.asp) maybe its an idea to change the wrong charactercode into the right one? (and in that way avoid working with the outputcharacters) function handleSpanishCharacters($input) { return str_replace("í", "é", $input); } Link to comment https://forums.phpfreaks.com/topic/211738-removingreplace-spanish-chars/#findComment-1103803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.