Compare two chains, apparently they are the same

2

I'm trying to compare 2 string . the first I get it from a array , the second I get it from reading a directory. The problem is that I'm trying to compare that the name of the array matches that of the file that is reading and are identical.

String from an array length: 30 something is changing.mp3 // element of the array

File read from Directory length: 23 something is changing.mp3 // file

I'm doing it with this code to compare them and it always throws me out that it's false. I do not know why they are different.

echo  "<br>Cadena proveniente de un array longitud de:  ".strlen(($arrayPosiciones[$x])). " ".  ($arrayPosiciones[$x]);
echo  "<br>Archivo leido de Directorio longitud de:".strlen(($d)). "  ".($d)  ;

I think it's because of an accent problem or something like that. I have tried in many ways. Even the array I put the htmlentities() since the elements that have tilde were badly encoded.

This fixes the problem, and the elements that are not shown in the tilde are fixed.

for($i=0; $i<count($arrayPosiciones); $i++){
    $arrayPosiciones[$i]=htmlentities($arrayPosiciones[$i]);
}

What can I do? I'm going through a directory and compare that the current file is the same as the one in the $ arrayPositions

$ruta=$_REQUEST['ruta'];
$dir =scandir($ruta);
foreach($dir as $d){
 if(substr($d,-3)=='Mp3' || substr($d,-3)=='mp3' || substr($d,-3)=='MP3' ||  substr($d,-3)=='WMA' || substr($d,-3)=
  for( $x=0; $x<count($arrayPosiciones); $x++){
    if($arrayPosiciones[$x]==$d){ echo "iguales"; }
.
.
.
    
asked by velez 08.04.2016 в 21:41
source

1 answer

2

If you have character encoding problems, you have to change all the character encoding of apache, php, mysql, html:

In Apache:

[httpd.conf]

AddDefaultCharset utf-8

In some versions of apache, AddDefaultCharset is not found in the usual place and you have to search for $ cfg ['DefaultCharset'] = ''; in the whole installation or similar variables and change it to $ cfg ['DefaultCharset'] = 'utf-8' ;

In php:

[php.ini]

default_charset = "utf-8"
mbstring.internal_encoding=utf-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On
mbstring.func_overload=0

If you are using a version higher or equal to php 5.6 these parameters are obsolete:

mbstring.internal_encoding
mbstring.http_input
mbstring.http_output

and just put default_charset="utf-8"

If you use mysql all the collation of Database and tables must be utf8 - utf8_spanish_ci and in the connection:

$Conex=new mysqli(.....);
$Conex->set_charset("utf8");

Finally, your html must also configure utf8 with the following line:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

This will work perfectly in linux but if you use windows and try to write files to disk you will see that it does not work (because windows uses another encoding). It is then when you have to resort to the large repertoire of functions that PHP has for character encoding, in this case iconv. Example: when writing to disk;

 $nombre="ññ.txt"
    $f2=fopen(iconv("UTF-8", "ISO-8859-1",$nombre),"w"); 
    fwrite($f2,$texto);
    fclose($f2);

or when reading from disk;

$tam=filesize(iconv("UTF-8", "ISO-8859-1",$nombre));
    
answered by 20.04.2016 в 01:18