<object classid="clsid:d27cdb6e-ae6d" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="120" height="50" id="vote" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="http://www.votxo.com/votes/french-y.swf?id=16336" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<param name="wmode" value="transparent" />
<embed src="http://www.votxo.com/votes/french-y.swf?id=16336" quality="high" bgcolor="#FFFFFF" width="120" height="50" name="vote" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="transparent" /> </object>
<?php
class fiche implements JsonSerializable{
private $numero;
private $titre;
private $text;
// d'autre trucs si tu veux
public function __construct(){
//
}
public function getNumero(){
return $this->numero;
}
public function getTitre(){
return $this->titre;
}
public function getText(){
return $this->text;
}
public function setNumero($num){
$this->numero = $num;
}
public function setTitre($titre){
$this->titre=$titre;
}
public function setText($txt){
$this->text = $txt;
}
public function jsonSerialize(){
return ['numero'=>$this->getNumero(),'texte'=>$this->getText(),'titre'=>$this->getTitre()];
}
}
$f1 = new fiche();
$f1->setNumero(12);
$f1->setText('du blabla
sur plusieurs
meme si
tu veux');
$f1->setTitre('le titre');
$encode = json_encode($f1);
var_dump($encode);
$decode = json_decode($encode);
var_dump($decode);
exemple basique sans contrôle de champs et surement pas adapterCode : Tout sélectionner
string '{"numero":12,"texte":"du blabla \r\n\t\tsur plusieurs\r\nmeme si \r\n\t\ttu veux","titre":"le titre"}' (length=100)
object(stdClass)[2]
public 'numero' => int 12
public 'texte' => string 'du blabla
sur plusieurs
meme si
tu veux' (length=47)
public 'titre' => string 'le titre' (length=8)<?php
class fiche implements JsonSerializable{
private $numero;
private $titre;
private $text;
// d'autre trucs si tu veux
public function __construct(){
//
}
public function getNumero(){
return $this->numero;
}
public function getTitre(){
return $this->titre;
}
public function getText(){
return $this->text;
}
public function setNumero($num){
$this->numero = $num;
}
public function setTitre($titre){
$this->titre=$titre;
}
public function setText($txt){
$this->text = $txt;
}
public function jsonSerialize(){
return ['numero'=>$this->getNumero(),'texte'=>$this->getText(),'titre'=>$this->getTitre()];
}
}
$f1 = new fiche();
$f1->setNumero(12);
$f1->setText('du blabla
sur plusieurs
meme si
tu veux');
$f1->setTitre('le titre');
$encode = json_encode($f1);
echo $encode;
le fichier "distant"
<?php
$encode = file_get_contents('http://localhost/test/juliette2.php');
$decode = json_decode($encode);
var_dump($decode);
affiche
Code : Tout sélectionner
object(stdClass)[1]
public 'numero' => int 12
public 'texte' => string 'du blabla
sur plusieurs
meme si
tu veux' (length=47)
public 'titre' => string 'le titre' (length=8)