How unencode database special characters ? How unencode database special characters ?
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

How unencode database special characters ?

Started by scheinarts, April 24, 2007, 02:57:04 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

scheinarts

I built simple mysql php script that will create rows of data from the coppermine database. The purpose is to create an Easy Populate file for osCommerce. So far so good.
The problem is that the Categories and albums names are in spanish (with special characters like á é í ó ú and ñ only). The result from the query is outputting this data like Vehículos instead of Vehículos, montaña instead of montaña and so on. How do I unencode these characters so that the output put is the correct special character.
Here is the code im am using...


$query = "SELECT *, `cpg1410_pictures`.`title` AS `title_pic` FROM ((cpg1410_pictures LEFT JOIN cpg1410_albums ON cpg1410_pictures.aid = cpg1410_albums.aid) LEFT JOIN cpg1410_categories ON cpg1410_albums.category = cpg1410_categories.cid)";

$result = mysql_query($query) or die(mysql_error());

echo '<table>';

while($row = mysql_fetch_array($result)) {

echo '<tr><td width="100%">';
//1
echo $row['pid'] . ', ';
//2
echo $row['filepath'] . $row['filename'] . ', ';
//3
echo sprintf($row['title_pic']) . ', ';
//4
echo $row['keywords'] . ', ';
//5 6 7 8
echo ' , , , ,';
//9
echo $row['mtime'] . ', ';
//10
echo ' ,';
//11
echo $row['owner_name'] . ', ';
//12
echo $row['name'] . ', ';
//13
echo $title_d . ', ';
//14 15 16
echo ' , , ,EOREOR';

echo '</td></tr>';
}
echo '</table>';

This creates a nice file for Easy Populate, just in case some one is interested  ;)

Nibbler

If you need to convert the data into a different character set use iconv. Refer to the php manual for details.

scheinarts

thanks, looking into that right now, could you show an example using this function? it how it would be applied in this particular case?

Nibbler

Add it here, so


while($row = mysql_fetch_array($result)) {


would become



function convertme($string){
    return iconv('UTF-8', 'insert_desired_charset_here', $string);
}

while($row = mysql_fetch_array($result)) {

    $row = array_map('convertme', $row);


scheinarts

nice that worked like a charm! Thanks!
One more question, I know its stupid, but i am newbie at writing php... what is the $string variable for? since its not used anywhere else in the code?

Joachim Müller


scheinarts