[PHP] issue with accents and mysql

2005-02-15 Thread mario
Hello,

please help me on the following issue.
please reply to [EMAIL PROTECTED] too.
(I asked for help on the php-db ml, but nobody replied)

I have hacked the following function:
function accents($text) {
   global $export;
   $search  = array ( 'à', 'è', 'ì', 'ò' , 'ù');
   $replace = array ( '\\`{a}', '\\`{e}', '\\`{i}', '\\`{o}', '\\`{u}');
   $export= str_replace($search, $replace, $text);
   return $export;
}

It works fine, as long as I feed it with a string: 
accents('à') -- \`{a} 

The issue is when I get 'à' from a mysql table. 
I.e., for some record of a mysql table Table, let à the value of the
field Field, and say
$result =  mysql_fetch_array($answer, MYSQL_BOTH), 
where $answer= mysql_query(SELECT * FROM Table).


Now accents($result['Field']) returns à (instead of \`{a}).
Why? I have no idea. 

Any hint is welcome.
Thanks a lot
mario

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] issue with accents and mysql

2005-02-15 Thread Guillermo Rauch
Try
SHOW VARIABLES LIKE 'character_set%'

and verify your character set is latin1.

If not, see http://dev.mysql.com/doc/mysql/en/charset-database.html

On Tue, 15 Feb 2005 22:04:30 +, mario [EMAIL PROTECTED] wrote:
 Hello,
 
 please help me on the following issue.
 please reply to [EMAIL PROTECTED] too.
 (I asked for help on the php-db ml, but nobody replied)
 
 I have hacked the following function:
 function accents($text) {
   global $export;
   $search  = array ( 'à', 'è', 'ì', 'ò' , 'ù');
   $replace = array ( '\\`{a}', '\\`{e}', '\\`{i}', '\\`{o}', '\\`{u}');
   $export= str_replace($search, $replace, $text);
   return $export;
 }
 
 It works fine, as long as I feed it with a string:
 accents('à') -- \`{a}
 
 The issue is when I get 'à' from a mysql table.
 I.e., for some record of a mysql table Table, let à the value of the
 field Field, and say
 $result =  mysql_fetch_array($answer, MYSQL_BOTH),
 where $answer= mysql_query(SELECT * FROM Table).
 
 Now accents($result['Field']) returns à (instead of \`{a}).
 Why? I have no idea.
 
 Any hint is welcome.
 Thanks a lot
 mario
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] issue with accents and mysql

2005-02-15 Thread mario
Hi,

thanks, but that seems to be ok:
SQL result
Host: 127.0.0.1
Database : 
Generation Time: Feb 15, 2005 at 11:36 PM
Generated by: phpMyAdmin 2.5.7-pl1 / MySQL 3.23.58
SQL-query: SHOW VARIABLES LIKE 'character_set%'; 
Rows: 2 

   Variable_name 
   Value 
character_set
latin1
character_sets
latin1 big5 cp1251 cp1257 croat
czech danish dec8 ...

any further idea?
thanks
mario

ps of course, I could 
On Tue, 2005-02-15 at 21:42, Guillermo Rauch wrote:
 Try
 SHOW VARIABLES LIKE 'character_set%'
 
 and verify your character set is latin1.
 
 If not, see http://dev.mysql.com/doc/mysql/en/charset-database.html
 
 On Tue, 15 Feb 2005 22:04:30 +, mario [EMAIL PROTECTED] wrote:
  Hello,
  
  please help me on the following issue.
  please reply to [EMAIL PROTECTED] too.
  (I asked for help on the php-db ml, but nobody replied)
  
  I have hacked the following function:
  function accents($text) {
global $export;
$search  = array ( 'à', 'è', 'ì', 'ò' , 'ù');
$replace = array ( '\\`{a}', '\\`{e}', '\\`{i}', '\\`{o}', '\\`{u}');
$export= str_replace($search, $replace, $text);
return $export;
  }
  
  It works fine, as long as I feed it with a string:
  accents('à') -- \`{a}
  
  The issue is when I get 'à' from a mysql table.
  I.e., for some record of a mysql table Table, let à the value of the
  field Field, and say
  $result =  mysql_fetch_array($answer, MYSQL_BOTH),
  where $answer= mysql_query(SELECT * FROM Table).
  
  Now accents($result['Field']) returns à (instead of \`{a}).
  Why? I have no idea.
  
  Any hint is welcome.
  Thanks a lot
  mario
  
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] issue with accents and mysql

2005-02-15 Thread Bret Hughes
On Tue, 2005-02-15 at 17:40, mario wrote:
 Hi,
 
 thanks, but that seems to be ok:
 SQL result
 Host: 127.0.0.1
 Database : 
 Generation Time: Feb 15, 2005 at 11:36 PM
 Generated by: phpMyAdmin 2.5.7-pl1 / MySQL 3.23.58
 SQL-query: SHOW VARIABLES LIKE 'character_set%'; 
 Rows: 2 
 
Variable_name 
Value 
 character_set
 latin1
 character_sets
 latin1 big5 cp1251 cp1257 croat
 czech danish dec8 ...
 
 any further idea?
 thanks
 mario
 
 ps of course, I could 
 On Tue, 2005-02-15 at 21:42, Guillermo Rauch wrote:
  Try
  SHOW VARIABLES LIKE 'character_set%'
  
  and verify your character set is latin1.
  
  If not, see http://dev.mysql.com/doc/mysql/en/charset-database.html
  
  On Tue, 15 Feb 2005 22:04:30 +, mario [EMAIL PROTECTED] wrote:
   Hello,
   
   please help me on the following issue.
   please reply to [EMAIL PROTECTED] too.
   (I asked for help on the php-db ml, but nobody replied)
   
   I have hacked the following function:
   function accents($text) {
 global $export;
 $search  = array ( 'à', 'è', 'ì', 'ò' , 'ù');
 $replace = array ( '\\`{a}', '\\`{e}', '\\`{i}', '\\`{o}', '\\`{u}');
 $export= str_replace($search, $replace, $text);
 return $export;
   }
   
   It works fine, as long as I feed it with a string:
   accents('à') -- \`{a}
   
   The issue is when I get 'à' from a mysql table.
   I.e., for some record of a mysql table Table, let à the value of the
   field Field, and say
   $result =  mysql_fetch_array($answer, MYSQL_BOTH),
   where $answer= mysql_query(SELECT * FROM Table).
   
   Now accents($result['Field']) returns à (instead of \`{a}).
   Why? I have no idea.
   
   Any hint is welcome.
   Thanks a lot


I have no idea what might be the problem but I would probably start by
seeing what the difference is at the ascii level.

preg_split the strings and run ord on each one

foreach ( preg_split(//,this is a string) as $char ) {
echo The ascii value for $char is . ord($char) . \n;
}

post the results from both sources and lets see what can be found.

Bret

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] issue with accents and mysql

2005-02-15 Thread Burhan Khalid
mario wrote:
Hello,
please help me on the following issue.
please reply to [EMAIL PROTECTED] too.
(I asked for help on the php-db ml, but nobody replied)
I have hacked the following function:
function accents($text) {
   global $export;
   $search  = array ( 'à', 'è', 'ì', 'ò' , 'ù');
   $replace = array ( '\\`{a}', '\\`{e}', '\\`{i}', '\\`{o}', '\\`{u}');
   $export= str_replace($search, $replace, $text);
   return $export;
}
It works fine, as long as I feed it with a string: 
accents('à') -- \`{a} 

The issue is when I get 'à' from a mysql table. 
I.e., for some record of a mysql table Table, let à the value of the
field Field, and say
$result =  mysql_fetch_array($answer, MYSQL_BOTH), 
where $answer= mysql_query(SELECT * FROM Table).

Now accents($result['Field']) returns à (instead of \`{a}).
Why? I have no idea.
Try var_dump $text in accents() when you pass it $result['Field']
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php