/** * UTF-8 encodes all elements in an array * * @author Patrik "Popeen" Johansson <*****@*****.**> * * @license https://raw.githubusercontent.com/Kakadua/PHP-Snippets/master/LICENSE Unlicense * * @link https://github.com/Kakadua/PHP-Snippets/ * * @package Kakadua-PHP-Snippets * * @param array $array An array * * @return array An array * * @version 1 */ function utf8_encode_all($inputArray) { if (is_string($inputArray)) { return utf8_encode($inputArray); } if (!is_array($inputArray)) { return $inputArray; } $outputArray = array(); foreach ($inputArray as $i => $d) { $outputArray[$i] = utf8_encode_all($d); } return $outputArray; }
function api_get($var) { if ($var == "list") { include "db_config.php"; mysql_set_charset('UTF8'); $conn = mysql_connect($DB_host, $DB_login, $DB_pass); $db = mysql_select_db($DB_select, $conn); if (!$conn) { die('Erreur de connexion: ' . mysql_error()); } $SQL = "SELECT * FROM actualite"; $reponse = mysql_query($SQL); //$bdd = new PDO('mysql:host=localhost;dbname=demainp', 'root', ''); //$reponse = $bdd->query("Select * From actualite"); $dbResult_utf8 = array(); while ($donnees = mysql_fetch_array($reponse)) { $donnees = cleanLigne($donnees); $ligneUtf8 = utf8_encode_all($donnees); array_push($dbResult_utf8, $ligneUtf8); } print json_encode($dbResult_utf8); } else { include "db_config.php"; mysql_set_charset('UTF8'); $conn = mysql_connect($DB_host, $DB_login, $DB_pass); $db = mysql_select_db($DB_select, $conn); if (!$conn) { die('Erreur de connexion: ' . mysql_error()); } $SQL = "Select * From actualite where aid={$var}"; $reponse = mysql_query($SQL); //$bdd = new PDO('mysql:host=localhost;dbname=demainp', 'root', ''); //$reponse = $bdd->query("Select * From actualite where aid=$var"); $dbResult_utf8 = array(); while ($donnees = mysql_fetch_array($reponse)) { $donnees = cleanLigne($donnees); $ligneUtf8 = utf8_encode_all($donnees); array_push($dbResult_utf8, $ligneUtf8); } print json_encode($dbResult_utf8); } }