...

View Full Version : Encode spanish characters in html and display



titanic_fanatic
12-20-2006, 06:14 PM
I have a script that is currently serving as a course content management system which simply displays all media in a directory in a list of links that look like this index.php?action=showfile&filename=filename.mp3&type=mp3

where type determines wich directory to look for filename.mp3 (audio) and filename is of course the filename.

for this filename.mp3 file, it would also be accompanied by a filename.mp3.dia which is only a text file with spanish text.

I need to read this text file and encode all special characters into html which I have accomplished by using this little bit of code:


function encode_dialogue($file){

$lines = file($file);

foreach ($lines as $key => $value){

$encoded_value = encode_accents($value);
$lines[$key] = $encoded_value;

header("Content-type: text/html");
$dia .= $lines[$key];

}

return $dia;

}

function encode_accents($text){

foreach(get_html_translation_table(HTML_ENTITIES) as $a=>$b){

$text = str_replace($a,$b,$text);

}

return $text;

}

I call the function encode_dialogue() like this:


$myVariable = encode_dialogue($url_to_filename.mp3.dia);

When I call the variable $myVariable in my php generated html page, the text appears except the html codes like:


¡

just display like this and aren't parsing???

any Ideas???

mlseim
12-20-2006, 08:45 PM
You mention a PHP generated page ...

Show us more about that part, how you generate the page.
Are you defining this in your generated page?
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">

titanic_fanatic
12-21-2006, 09:46 AM
You mention a PHP generated page ...

Show us more about that part, how you generate the page.
Are you defining this in your generated page?
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">

I just figured out what the problem was... it was for some reason changing all of the & to &amp; and screwing up everything so I changed this function:



function encode_accents($text){

foreach(get_html_translation_table(HTML_ENTITIES) as $a=>$b){

$text = str_replace($a,$b,$text);

}

return $text;

}


to this function:



function encode_accents($text){

foreach(get_html_translation_table(HTML_ENTITIES) as $a=>$b){

if ($b != "&amp;"){

$text = str_replace($a,$b,$text);

}

}

return $text;

}


and now it works just fine...

thanks hint on encoding, that kind of what made me dig a little more...

Titanic_Fanatic



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum