Jump to content

Removing/replace Spanish chars


williamZanelli

Recommended Posts

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

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("&#xED;", "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

hey Wil,

 

what i dont understand is that for example é is changed into &#xED; as the right code would be &#233; (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("&#xED;", "&#233;", $input);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.