Javascript :
https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/encodeURI
Formatage :
https://beautifier.io/ et https://www.freeformatter.com/javascript-beautifier.html
Dates :
<?php $jour = array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi"); $mois = array("","Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"); $datefr = $jour[date("w")]." ".date("d")." ".$mois[date("n")]." ".date("Y"); echo "Nous sommes le ". $datefr."\n"; ///////////////////////// $JenPlus=128; $JenMoins=-300; $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d'); $Jour_prev_date = date('w', strtotime($date .' '.$JenMoins.' day')); $JJ_prev_date = date('d', strtotime($date .' '.$JenMoins.' day')); $AA_prev_date = date('Y', strtotime($date .' '.$JenMoins.' day')); $MM_prev_date = date('m', strtotime($date .' '.$JenMoins.' day')); $JJ_next_date = date('d', strtotime($date .' '.$JenPlus.' day')); $MM_next_date = date('m', strtotime($date .' '.$JenPlus.' day')); $AA_next_date = date('Y', strtotime($date .' '.$JenPlus.' day')); $Jour_next_date = date('w', strtotime($date .' '.$JenPlus.' day')); // $prev_date = date('Y-m-d', strtotime($date .$JenMoins.' day')); $next_date = date('Y-m-d', strtotime($date .$JenPlus.' day')); // echo "\n"."Variation de ".$JenMoins." jour :"."\n"; echo "Jour =".$JJ_prev_date." Mois =".$MM_prev_date." Date = ".$prev_date." le ". $jour[intval($Jour_prev_date)]." ".$JJ_prev_date." ".$mois[intval($MM_prev_date)]." ".$AA_prev_date."\n"; echo "Et ".$JenPlus." jours :"."\n"; echo "Jour =".$JJ_next_date." Mois =".$MM_next_date." Date = ".$next_date." le ". $jour[intval($Jour_next_date)]." ".$JJ_next_date." ".$mois[intval($MM_next_date)]." ".$AA_next_date."\n"; ?>
Donne :
Nous sommes le Mardi 04 Septembre 2018
Variation de -300 jour :
Jour =08 Mois =11 Date = 2017-11-08 le Mercredi 08 Novembre 2017
Et 128 jours :
Jour =10 Mois =01 Date = 2019-01-10 le Jeudi 10 Janvier 2019
Pour retirer les ‘0’ :
$date = isset($_GET[‘date’]) ? $_GET[‘date’] : date(‘Y-m-d’);
$jour_actu = date(‘d’, strtotime($date));
$jour_actu = substr($jour_actu, strpos($jour_actu, « 0 ») + 1);
Pour rechercher une chaîne dans une autre :
<?php
$mystring = ‘abc’;
$findme = ‘a’;
$pos = strpos($mystring, $findme);// Notez notre utilisation de ===. == ne fonctionnerait pas comme attendu
// car la position de ‘a’ est la 0-ième (premier) caractère.
if ($pos === false) {
echo « La chaîne ‘$findme’ ne se trouve pas dans la chaîne ‘$mystring' »;
} else {
echo « La chaine ‘$findme’ a été trouvée dans la chaîne ‘$mystring' »;
echo » et débute à la position $pos »;
}
?>
Production de JSON avec du texte accentué :
class Emp {
public $uid = « uid »;
public $updateDate = « updateDate »;
public $titleText = »titleText »;
public $mainText = « mainText »;
}
$date = new DateTime();
$dtJour = $date->format(‘Y-m-d\TH:i:s\Z’);
$jour = array(« Dimanche », »Lundi », »Mardi », »Mercredi », »Jeudi », »Vendredi », »Samedi »);
$mois = array(« », »Janvier », »Février », »Mars », »Avril », »Mai », »Juin », »Juillet », »Août », »Septembre », »Octobre », »Novembre », »Décembre »);
$datefr = $jour[date(« w »)]. » « .date(« d »). » « .$mois[date(« n »)];
$texte_speech= »Aujourdhui « .$datefr;
$e = new Emp();
$e->uid = gen_uuid(); // »a3317174-ade9-11e8-8492-4a124eda53b1″;
$e->updateDate = $dtJour; // »2018-09-01T13:19:21.0Z »;
$e->titleText = « Jour »;
$e->mainText = $texte_speech;
/////////// JSON production
header(‘Content-type:application/json;charset=utf-8’);
$res= json_encode($e, JSON_UNESCAPED_UNICODE);
Remplacement de carractères :
$sTxt= »bla, toto »;
echo $sTxt. »\n »;
$txt = str_replace(« , », » et », $sTxt);
echo $txt. »\n »;
JSON :
Pour rechercher un json : http://www.jsonquerytool.com/#/JavaScript
Pour valider un json : http://freeonlinetools24.com/json-decode
Et https://www.freeformatter.com/json-formatter.html
Pour lire le résultat d’un appel d’url retournant un JSON :
function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, « Mozilla/5.0 (Windows; U; Windows NT 5.1; fr-FR; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 »);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}$res=getSslPage($urlw);
$json_data = json_decode($res);
Emultateur test PHP Online : http://sandbox.onlinephpfunctions.com/code/6527cbe81268e51daa321b81157f370879d038b8
http://sandbox.onlinephpfunctions.com/
Références :
http://hypermedia.univ-paris8.fr/jean/internet/ex_table.html