Validation in_array with Ç

Asked

Viewed 25 times

0

I have an array:

$enderecos  = array( 'Endereço', 'Endereco', 'Endereço ' );

Use the function fgetcsv to read my CSV, I check the csv header by comparing whether the header is included in the array.

    if(in_array($colunas_csv, $enderecos))
    {
        $endereco_posicao = $key;
    }

Where $colunas_csv is the header return, what happens is that if the returned header is Endereco verification occurs, but, if it is Endereço does not occur due to Ç.

  • But the $colunas_csv is in UTF-8? If not, what encoding is used?

1 answer

0

You can draw on this example:

<?php
        $arr = ["Endereco","Endereço","Não", "Olá"];
        $decode = implode(' ', $arr);
        $Format = array();
        $Format['a'] = 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜüÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿRr"!@#$%&*()_-+={[}]/?;:.,\\\'<>°ºª'; //Pega tudo que tiver acento
        $Format['b'] = 'aaaaaaaceeeeiiiidnoooooouuuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr                                 '; //Todos os itens do Format['b'] vão ser substituidos por esses
        $Data = strtr(utf8_decode($decode), utf8_decode($Format['a']), utf8_decode($Format['b'])); //Faz a substituição
        $Final = trim(strip_tags($Data)); //Limpa a string de espaços iniciais e finais e de codigos html/JS/PHP
        echo $Final;

?>

What will be printed: Endereco Endereco Nao Ola

I tried to explain with comments to make it easier to understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.