Advanced search  

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]

Pages: [1]   Go Down

Author Topic: How unencode database special characters ?  (Read 3417 times)

0 Members and 1 Guest are viewing this topic.

scheinarts

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
How unencode database special characters ?
« 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  ;)
« Last Edit: April 24, 2007, 12:58:51 pm by GauGau »
Logged

Nibbler

  • Guest
Re: How unencode database special characters ?
« Reply #1 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.
Logged

scheinarts

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How unencode database special characters ?
« Reply #2 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?
Logged

Nibbler

  • Guest
Re: How unencode database special characters ?
« Reply #3 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);

Logged

scheinarts

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How unencode database special characters ?
« Reply #4 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?
Logged

Joachim MŘller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: How unencode database special characters ?
« Reply #5 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
Logged

scheinarts

  • Coppermine newbie
  • Offline Offline
  • Posts: 18
Re: How unencode database special characters ?
« Reply #6 on: April 24, 2007, 10:01:57 am »

Thanks GauGau for that link.
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 22 queries.