laviku
laviku

Reputation: 541

Why two words don't match when they're the same?

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

Upvotes: 0

Views: 98

Answers (3)

Hdhams
Hdhams

Reputation: 24

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";

  ?>

Upvotes: 0

Robert Owen
Robert Owen

Reputation: 930

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);

Upvotes: 0

Aswin Murugesh
Aswin Murugesh

Reputation: 11070

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

Upvotes: 0

Related Questions