str_replace 在 html 代码中不起作用

发布于 2024-12-22 01:50:19 字数 612 浏览 8 评论 0原文

我正在使用一个表单,它的字段之一是 RTF 文本区域(jWYSIWYG),它在页面加载时自动填充一些数据库信息,所有这些都使用 Symfony 框架。这个RTF编辑器可以添加一些html标签,如

等。

当我试图知道文本区域之前是否被修改过时,麻烦就开始了发送表单:我从 $request 得到的是所有 html 标签的编码如下&lt;p&gt;&lt;b&gt; 等。我尝试用 < 替换这些表达式> 和 > 字符,以便我可以将其与存储的数据进行比较。

$codes = array('&gt;','&lt;');
$chars = array('<'   ,'>' );
return str_replace($codes,$chars,$text);

但这个函数返回的数组与我作为 str_replace 函数的参数传递的数组相同。我做错了什么?有人遇到同样的问题吗?

i'm working with a form one of its fields is an RTF textarea (jWYSIWYG), that is autofilled with some database information at the load of the page, all that using Symfony framework. This RTF editor can add some html tags like <p>,<b>, etc.

The trouble starts when i try to know if the textarea has been modified before sending the form: what i get from the $request is that all the html tags are coded like <p>,<b>, etc. I tryed to replace that expressions with the < and > characters so i can compare it to the stored data.

$codes = array('>','<');
$chars = array('<'   ,'>' );
return str_replace($codes,$chars,$text);

but this function returns me the same array i pass as parameter of the str_replace function. What am I doing wrong? have anyone had the same problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

北城挽邺 2024-12-29 01:50:19

终于发现问题了。与 html 标签无关!问题是(我不知道为什么)jWYSIWYG 在字段末尾添加了大约 24 个空格,因此显然,存储数据和新数据之间的比较结果不同。

我只是这样删除了输入的最后空格:

$text = rtrim($text);

Finally discovered the problem. Was not about the html tags! the problem is (i dont know why) the jWYSIWYG adds about 24 white spaces at the end of the field, so obvously, the comparation between stored and new data results different.

i simply deleted the final whitespaces of the input this way:

$text = rtrim($text);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文