2

您好,我有这个字符串,它是一系列代码/参考:

<?PHP

$list="1010<1>;1020<?>;3010<?>";  the list of items code
$id="5060<?>"; //will add this 

$list_unique=explode(";", $list); 


print_r($list_unique);

?>

现在输出是: Array ( [0] => 1010<1> [1] => 1020 [2] => 3010 ) 为什么?它忘记了为什么?它应该是

数组( [0] => 1010<1> [1] => 1020< ?> [2] => 3010< ?> )

4

2 回答 2

6

您可能正在将输出视为呈现的 HTML。查看源代码,您会发现它没有丢失。

或者,在检查输出时转义它。

echo htmlspecialchars( print_r($list_unique, 1 ) );
于 2013-11-13T10:41:14.630 回答
4

如果你不确定你的结果,总是var_dump($yourvar);而不是。print_r($yourvar);

var_dump($list_unique);给了我这个

array(3) {
  [0]=>
  string(7) "1010<1>"
  [1]=>
  string(7) "1020<?>"
  [2]=>
  string(7) "3010<?>"
}
于 2013-11-13T10:44:20.390 回答