Forum Moderators: coopster

Message Too Old, No Replies

Problem with PHP while saving UTF-8 contents

UTF-8 not displaying correctly from db in Flash

         

Mrricky

7:29 pm on Feb 17, 2006 (gmt 0)



Hi I am in a real rush and need to sort this one out really quickly. So i would appreciate every idea about it. Thanks

The objective
Present db content inside a flash movie

The problem
The db content is Portuguese text so UTF-8 with special characters like ú, á, etc.

The situation so far
I have managed to develop a flash movie clip that loads html or plain text with or without special characters. But when the process of retrieving from the db gets done with PHP instead of manually creating a txt file saved as UTF-8 the thing breaks!

Schematically the process is php gets the db content and writes a file.txt the flash reads this file and displays it.

Now I am sure that the flash side works because: if I "point" the flash movie at a file with special characters created and saved in UTF-8 by me, it displays it.

While having php to create the file it doesn't!

Here is the php code that I am using:


<?
require_once('connections/Site.php');

// NOTICIAS RECORDSET
mysql_select_db($database_Site, $Site);
$query_noticias = "SELECT * FROM Noticias ORDER BY Id ASC";
$noticias = mysql_query($query_noticias, $Site) or die(mysql_error());
$row_noticias = mysql_fetch_assoc($noticias);
$totalRows_noticias = mysql_num_rows($noticias);

/*

Outputs a fragment of the text split after a space after $by amount of
characters

*/
function cut($string, $by) {
$scan = 0;
$pure_text = strip_tags($string);
$pure_text2 .= utf8_encode($pure_text);

if (strlen($pure_text2) >= $by){
while ($scan == 0) {
if (substr($pure_text2, $by, 1) == ' ')
$scan = 1;
else
$by++;
}
}

return substr($pure_text2, 0, $by) . "...";
}

if ($totalRows_noticias!= 0)
do {
$content .= "&content=<p style=\"font:Verdana, Arial, Helvetica, sans-serif; font-size:0.7em; font-weight:bold; color:#FFFFFF;\"><a target=\"_blank\" href=\"noticia.php?Id=".$row_noticias['Id']."\">".cut($row_noticias['Texto'], 300)."</a></p>";
} while ($row_noticias = mysql_fetch_assoc($noticias));
echo $row_noticias['Texto'];

$filename = 'noticias.txt';

if (is_writable($filename)) {

if (!$handle = fopen($filename, 'w')) {
echo "Cannot open file ($filename)";
exit;
}

if (!fputs($handle, $content)) {
echo "Cannot write to file ($filename)";
exit;
}

echo "Success, wrote ($content) to file ($filename)";

fclose($handle);

} else {
echo "The file $filename is not writable";
}


mysql_free_result($noticias);
?>

coopster

8:13 pm on Feb 21, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Mrricky.

Have you had a look at the data being stored in the table? Perhaps it is in the writing of the data, not the retrieval, where the issue lies.