Sujet : php var_dump VS python repr !
408 lectures
Par harobed, vendredi 12 mars 2010 à 16:13 :: Hacking :: #231 :: rss
Un exemple en Php :
<?php
$a = 'bar "test" bar';
var_dump($a);
// Sortie : string(14) "bar "test" bar"
$b = 'bar \'test\' bar';
var_dump($b);
// Sortie : string(14) "bar 'test' bar"
$c = 'bar \'test\' "test" bar';
var_dump($c);
// Sortie : string(21) "bar 'test' "test" bar"
$d = array(
'foo' => 'bar \'test\' "test" bar'
);
var_dump($d);
/* Sortie :
array(1) {
["foo"]=>
string(21) "bar 'test' "test" bar"
}
*/
?>
la sortie de ce script :
string(14) "bar "test" bar"
string(14) "bar 'test' bar"
string(21) "bar 'test' "test" bar"
array(1) {
["foo"]=>
string(21) "bar 'test' "test" bar"
}
Même chose en Python :
>>> a = 'bar "test" bar'
>>> print(repr(a))
'bar "test" bar'
>>> b = 'bar \'test\' bar'
>>> print(repr(b))
"bar 'test' bar"
>>> c = 'bar \'test\' "test" bar'
>>> print(repr(c))
'bar \'test\' "test" bar'
>>> d = { 'foo': 'bar \'test\' "test" bar' }
>>> print(d)
{'foo': 'bar \'test\' "test" bar'}
Observatons :
- PHP oublie d'afficher les caractères d'échappements
- Python affiche correctement les caractères d'échappements
- Python prend soin d'afficher au mieux les guillemets : soit utilise des simples "quotes" ou des "double quotes"








Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire