ERG::Code-2018-2
Aller à la navigation
Aller à la recherche
Projets
La fétichisation de l'Objet - Quentin Lamouroux
Impression Alternative - Anthony Pauwels
Máquina do tempo - Sofia Erzini
Partition Graphique - Jade Rouanet
Histoire de l'écran - Frédéric Jaman
Scripts démos
Un script php pour analyser un fichier json de conversations Messenger
function fixBadUnicodeForJson($str) {
$str = preg_replace_callback(
'/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/',
function($matches) { return chr(hexdec("$1")).chr(hexdec("$2")).chr(hexdec("$3")).chr(hexdec("$4")); },
$str
);
$str = preg_replace_callback(
'/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/',
function($matches) { return chr(hexdec("$1")).chr(hexdec("$2")).chr(hexdec("$3")); },
$str
);
$str = preg_replace_callback(
'/\\\\u00([0-9a-f]{2})\\\\u00([0-9a-f]{2})/',
function($matches) { return chr(hexdec("$1")).chr(hexdec("$2")); },
$str
);
$str = preg_replace_callback(
'/\\\\u00([0-9a-f]{2})/',
function($matches) { return chr(hexdec("$1")); },
$str
);
return $str;
}
function textConverter($str){
$str = utf8_decode(fixBadUnicodeForJson($str));
return $str;
}
$data = file_get_contents("tiina.json");
$data_traitee = json_decode($data);
//echo $data_data_traitee;
//print_r($data_traitee);
//echo $data_traitee->participants[0]->name;
echo $data_traitee->messages[5]->content;
foreach($data_traitee->messages as $message){
//echo '<p class="message">'.textConverter($message->content).'</p>';
//echo "<p class=\"message\">$message->content</p>";
$test1 = strpos($message->content, 'non');
$test2 = strpos($message->content, 'pas');
if($test1 != false && $test2 != false){
echo '<p class="message">'.textConverter($message->content).'</p>';
}
}
?>