par
Cyrano » 15 mai 2008, 22:28
En (apparemment) plus long mais plus propre et avec la syntace HEREDOC, ça aurait donné ceci :
function dsp_crypt($cfg=0,$reload=1)
{
// Affiche le cryptogramme
$sid = SID;
$str = <<<CHAINE
<table>
<tr>
<td>
<img id="cryptogram" src="{$_SESSION['cryptdir']}/cryptographp.php?cfg={$cfg}&{$sid}'>
</td>
CHAINE;
if ($reload)
{
$title = ($reload != 1) ? $reload : null;
$str .= <<<CHAINE
<td>
<a title="{$title}" style="cursor:pointer" onclick="document.images.cryptogram.src='{$_SESSION['cryptdir']}/cryptographp.php?cfg={$cfg}&{$sid}&'+ Math.round(Math.random(0)*1000)+1"><img src="{$_SESSION['cryptdir']}/images/reload.png"></a>
</td>
CHAINE;
}
$str .= <<<CHAINE
</tr>
</table>
CHAINE;
return $str;
}
Pour info, j'ai réalisé une proportion plus que notable de la nouvelle version du site
www.auchandirect.fr : je n'ai utilisé pratiquement que ce système avec HEREDOC. C'est très facile de travailler avec ça si on est un peu discipliné coté HTML/JavaScript/CSS ainsi que coté PHP bien entendu.
En (apparemment) plus long mais plus propre et avec la syntace HEREDOC, ça aurait donné ceci :
[php]function dsp_crypt($cfg=0,$reload=1)
{
// Affiche le cryptogramme
$sid = SID;
$str = <<<CHAINE
<table>
<tr>
<td>
<img id="cryptogram" src="{$_SESSION['cryptdir']}/cryptographp.php?cfg={$cfg}&{$sid}'>
</td>
CHAINE;
if ($reload)
{
$title = ($reload != 1) ? $reload : null;
$str .= <<<CHAINE
<td>
<a title="{$title}" style="cursor:pointer" onclick="document.images.cryptogram.src='{$_SESSION['cryptdir']}/cryptographp.php?cfg={$cfg}&{$sid}&'+ Math.round(Math.random(0)*1000)+1"><img src="{$_SESSION['cryptdir']}/images/reload.png"></a>
</td>
CHAINE;
}
$str .= <<<CHAINE
</tr>
</table>
CHAINE;
return $str;
}[/php]
Pour info, j'ai réalisé une proportion plus que notable de la nouvelle version du site www.auchandirect.fr : je n'ai utilisé pratiquement que ce système avec HEREDOC. C'est très facile de travailler avec ça si on est un peu discipliné coté HTML/JavaScript/CSS ainsi que coté PHP bien entendu.