forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: scheinarts on April 24, 2007, 02:57:04 am

Title: How unencode database special characters ?
Post by: scheinarts on April 24, 2007, 02:57:04 am
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...

Code: [Select]
$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  ;)
Title: Re: How unencode database special characters ?
Post by: Nibbler on April 24, 2007, 03:07:05 am
If you need to convert the data into a different character set use iconv. Refer to the php manual for details.
Title: Re: How unencode database special characters ?
Post by: scheinarts on April 24, 2007, 03:13:24 am
thanks, looking into that right now, could you show an example using this function? it how it would be applied in this particular case?
Title: Re: How unencode database special characters ?
Post by: Nibbler on April 24, 2007, 03:20:01 am
Add it here, so

Code: [Select]
while($row = mysql_fetch_array($result)) {

would become

Code: [Select]

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

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

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

Title: Re: How unencode database special characters ?
Post by: scheinarts on April 24, 2007, 03:28:50 am
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?
Title: Re: How unencode database special characters ?
Post by: Joachim Müller on April 24, 2007, 07:53:43 am
That's how functions work in PHP - see http://www.php.net/manual/en/language.functions.php
Title: Re: How unencode database special characters ?
Post by: scheinarts on April 24, 2007, 10:01:57 am
Thanks GauGau for that link.