gpt4 book ai didi

php - 检查字符串和 htmlentities 中的所有内容

转载 作者:行者123 更新时间:2023-12-02 04:56:31 25 4
gpt4 key购买 nike

我正在尝试编写一个评论表单。

我正在考虑使用 strstr 来查找 <pre>存在,如果它确实使用 htmlentities 将其中的所有内容转换为 html 安全。

但我遇到了一个问题,即在 pre 中实际转换所有内容。

我的代码变成了true但是如何替换。

我正在查看 preg_replace,但我的正则表达式充其量真的很差 :)

例子:

$string = 'This is a form with <pre>Everything in this needs to be htmlentities() </pre> and everything outside needs to be normal.';

最佳答案

如果我答对了你的问题,那么这应该可行:

$string_new = preg_replace_callback(
'#<pre>([\\s\\S]+?)</pre>#',
create_function(
'$input',
'return "<pre>".htmlentities($input[1])."</pre>";'
),
$string
);

关于php - 检查字符串和 htmlentities 中的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17897695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com