0

I have to compare two words. The first word is "módulo" and the other one is "modulo". I've tried to replace the accent, then I realize the word never changed after call the method to replace the accent. I get the first word from two arrays. The first array from an unserialize array called tipo.

<? 
$tipo = unserialize(TIPO); 
$estado = unserialize(ESTADO);  ?>

The second array comes from a database result, $prop['propiedad_tipo'] propiedad_tipo is int type.

$tipo_dato = (@$prop['propiedad_tipo'])?$tipo[ $prop['propiedad_tipo'] ]:'';

Through this value I can access to an index from "tipo" array, this is where i get the word "módulo".

And when I do this

if($tipo_dato == 'módulo')
  $tipo_dato = 'modulo';

nothing happens :( please help.

Ps. sorry for my english :(

-- Maybe this helps

$tipo_dato = (@$prop['propiedad_tipo'])?strtolower($tipo[ $prop['propiedad_tipo'] ]):''; 
  echo serialize($tipo_dato); echo '<br>'.serialize('módulo');

The result is s:13:"módulo"; s:7:"módulo";

-- I've found the big error. When i serialized the array "TIPO" I used m&oacute;dulo I chaged it to módulo and then everything works fine... Thank you so much for your help

laviku
  • 531
  • 12
  • 32

3 Answers3

0

using

if($tipo_dato=='modulo')
    $tipo_dato='modulo';

makes no sense. It checks if the value is modulo, and then assigns modulo. Change it to

if($tipo_dato!='modulo')
    $tipo_dato='modulo';

or change it to

if($tipo_dato=='modulo')
     #do some other thing
Aswin Murugesh
  • 10,831
  • 10
  • 40
  • 69
0

Found this which looks quite useful for what you need:

function toASCII( $str )
{
    return strtr(utf8_decode($str), 
        utf8_decode(
        'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ'),
        'SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy');
}

Taken from How to remove accents and turn letters into "plain" ASCII characters?

Then you can use:

$tipo_dato = toASCII($tipo_dato);
Community
  • 1
  • 1
Robert Owen
  • 930
  • 7
  • 12
  • I did this and still return the word with the accent :( – laviku Apr 01 '13 at 16:58
  • I copied the módulo word into a test php file and it worked for me there so I am guessing that the reason your IF is not working is that it is not the same ASCII character – Robert Owen Apr 01 '13 at 19:05
  • When i serialized the array "TIPO" I used `módulo` I chaged it to módulo and then everything works fine – laviku Apr 02 '13 at 21:09
0

Its may be issue in value retreiving the through database sotry to find what value $tipo_dato get through database

   $tipo_dato = (@$prop['propiedad_tipo'])?$tipo[ $prop['propiedad_tipo'] ]:''; 
     echo "$tipo_dato";

I think its just the swaping concept where one method to try this simple code.

//initial check the value 
echo "$uid<br>";
echo "$bid";

//after the swaping the value 
$d=$uid;
$uid="$bid";
$bid="$d";

//final outcome
echo "$uid<br>";
 echo "$bid";

  ?>
Hdhams
  • 24
  • 5