Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: How unencode database special characters ?  (Read 3940 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.021 seconds with 20 queries.