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
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

Link to comment
Share on other sites

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);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.