Hi,
So I have this code...
The problem is that $data is correctly utf8, because i echo it and can see the correct string. However when I pass it to $name, this charset is broken.
If i wish now to display this new array, it shows question marks on the black diamond shaped figure.
Could you please maybe help me debug this code?
The php file has this in the header.
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<?php
$data = array();
$inc = 0;
$handle = @fopen("content_realisations.php", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
$data[$inc] = ($buffer);
$inc = $inc+1;
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
?>
<?php
//for ($i=0; $i<$inc; $i++){
$name = get_data($data, $inc);
//echo utf8_encode($name[5][2]);
echo $name[5][2];
// echo $values[1] . "<br>";
// echo $values[2] . "<br>";
echo '<pre>'; print_r($name); echo '</pre>';
//}
//echo $inc; $length = strlen(utf8_decode($data[22])); echo $length . "<br>"; echo $data[22][$length-3];
function get_data($data, $inc){
for ($row=0; $row<$inc; $row++){
if ($mode == 0){
$z=0; $y=0; $w=0;
$data2 = array();
for($i=0 ; $i< utf8_decode(strlen($data[$row])) ; $i++){
if (($data[$row][$i] == '>') and ($z < 3)){
$z++;
$data_start = $i;
//echo $i . "<br>";
}
if (($data[$row][$i] == '<') and ($y < 4)){
$y++;
$data_end = $i;
//echo $i . "<br>";
}
if ($data[$row][$i] == '"'){
$data2[$w] = $i;
$w++;
}
}
$file = substr($data[$row], $data2[2]+1, $data2[3]-$data2[2]-1);
$thumb = substr($data[$row], $data2[6]+1, $data2[7]-$data2[6]-1);
$id = substr($data[$row], $data2[0]+1, $data2[1]-$data2[0]-1);
//echo $id . "<br>";echo $file . "<br>";echo $thumb . "<br>";echo '<pre>'; print_r($data2); echo '</pre>';
$s = $data_start+1;
//echo $z . "<br>"; echo $y . "<br>"; echo $row . "<br>";
if ($s < $data_end and $z!=0 and $y!=0 and $id == "im") {
//$name[$row][0] = $row; //must change the index !!!!
while($s != $data_end){
$name[$row][$s-$data_start] = $data[$row][$s];
echo $data[$row][$s];
$s++;
}
}
}
$length = strlen(utf8_decode($data[$row]));
$a1=$data[$row][0] . $data[$row][1] . $data[$row][2];
//echo '<pre>'; print_r($a1); echo '</pre>';
//echo gettype($a1[0]), "\n";
$is_match = (similar_text($a1, "<!-") == 3) ;
if ($is_match == 1){
//echo "1";
$mode = 1;
}else{
if (similar_text($a1, "-->") == 3 or similar_text($data[$row][$length-3] . $data[$row][$length-2], "->") == 2){
$mode = 0;
}
//echo "0";
}
//echo $file . "<br>";
//echo $thumb . "<br>";
}
return $name;
}
?>