$fetched_column['title'] = str_replace(' ', '<SP>', $fetched_column['title']);
echo $fetched_column['title'] . '<br>';
当回声出它去除的white_space但不与<SP>
替换它。我猜是因为<
>
。不知道如何解决这个问题,所以它代替white_space回调出<SP>
?str_replace函数有特殊字符
$fetched_column['title'] = str_replace(' ', '<SP>', $fetched_column['title']);
echo $fetched_column['title'] . '<br>';
当回声出它去除的white_space但不与<SP>
替换它。我猜是因为<
>
。不知道如何解决这个问题,所以它代替white_space回调出<SP>
?str_replace函数有特殊字符
如果你看到view-source,你可以看到你的替换代码,但是因为HTML试图将它解析为某些东西(例如指令),所以你不会在解析的web视图中看到它。
您可以使用html实体完全是这个原因。
代码如下:
$fetched_column['title'] = str_replace(' ', '<SP>', $fetched_column['title']);
echo $fetched_column['title'] . '<br>';
是的,它像一个魅力一样工作,没有足够的分数来投票给你,但希望在不久的将来有人在同一个问题上绊倒在这个页面上。 – PirateTube
您需要使用htmlspecialchars()
或htmlentities()
功能,使之成为展示和<
>
。从技术上讲,它不应该是<SP>
,而是<SP>
。
更改您的代码:
echo htmlentities($fetched_column['title']) . '<br>';
或者你也可以在第一次尝试这样做,当你试图取代,因为正确的格式:
$fetched_column['title'] = str_replace(' ', '<SP>', $fetched_column['title']);
因为''看到作为浏览器的HTML标签,并不显示(查看源代码)。你想'<'和'>'。 –
AbraCadaver
您需要使用'htmlspecialchars()'函数将其显示为'<'和'>'。从技术上讲,它不应该是'',而应该是'<SP>'。 –
你不应该使用str_replace它已被弃用的功能。你应该使用preg_replace而不是 – Peter