Forum Moderators: coopster
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);
?>