Hello,
I have country names (in french with accents and all), and I want to make a link between that, and names in upper case, without accents.
At first I thought it would be VERY easy to do:

I take the list of french names from my database.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$name = $row['french_name'];
$name = strtr($name, 'éèàï', 'eeai');
$name = strtoupper($name);
//do something with the $name
}

The problem is... after strtr (or str_replace, or any replacing function), the variable still contains accuented letters...

The name in the database: Brésil
The name after strtr AND strtoupper: BRÉSIL

But If I test the functions like this:
$test = 'été';
$test = strtr($test, 'é', 'e');
echo $test;
I get: ete...

So, why does it work when I assign a string to a variable manually, but NOT when I get the string from a MySQL ressource?
It is really really weird.
I checked, and my variable is a string, I tried settype and other stuff, but nothing worked...

    maybe try eregi_replace.

    But thats case_insentive and will change the lower and uppercase.

    I think your gonna have to live with it, unless someone else knows

      As I couldn't get replacement functions to work, I made my own piece of script to replace specific letters in a string.
      I wanted to test it only with the letter "é", so here it is:

      $query = "SELECT name_fr
      FROM i_countries";
      $result = mysql_query($query) or die (mysql_error());
      while (list($cname) = mysql_fetch_row($result)) {
      // $cname = "ééé";

       var_dump($cname);
       echo $cname.' - ';
      
       $i = 0;
       while ($cname[$i]) {
      if ($cname[$i] == "é") {
           $cname[$i] = 'e';
      }
      $i++;
       }
       echo $cname;
       echo '<br>';

      }

      If I execute this script, I'll get something like this:
      string(9) "Argentine" Argentine - Argentine
      string(6) "Brésil" Brésil - Brésil
      ...

      Note that the "é" in Brésil did not get changed to an "e"...

      If I uncomment the commented line, I'll get:
      string(3) ",t," ,t, - eee
      string(3) ",t," ,t, - eee
      ...

      So my function works, as it changes all "é" to "e".
      The only thing is that it displays a "," instead of a "é" in the browser: in HTML a "é" is written &eacute;

      But why, oh why doesn't it work when the string comes from the database ???

      The question should rather be:
      How is the "é" different when I assign from the database, and when I assign manually ??? In one case it displays well in HTML, and in the other case it doesn't: this is the proof that they are not seen the same way !

        Write a Reply...