php – 数组内爆’<',奇怪的行为
作者:互联网
$b = array("one", "two", "three");
$z = implode('<', $b);
var_dump($z);
输出:字符串(13)“一个
任何人都可以解释这个
PHP 5.4.4
解决方法:
查看html源结果,真正的结果是:
string(13) "one<two<three"
如所提到的:
This is what it is supposed to do. You are looking at it in your
browser, where it doesn’t show you the results as-is, but tries to
render it as HTML.
所以如果你想把它看作纯文本,那么简单的过滤html标签:
<?php
$b = array("one", "two", "three");
$z = implode('<', $b);
$z = htmlspecialchars($z);
var_dump($z);
标签:php,arrays,implode 来源: https://codeday.me/bug/20190620/1247097.html