str_replace 在 html 代码中不起作用
我正在使用一个表单,它的字段之一是 RTF 文本区域(jWYSIWYG),它在页面加载时自动填充一些数据库信息,所有这些都使用 Symfony 框架。这个RTF编辑器可以添加一些html标签,如
、
等。
当我试图知道文本区域之前是否被修改过时,麻烦就开始了发送表单:我从 $request
得到的是所有 html 标签的编码如下<p>
、<b>
等。我尝试用 <
替换这些表达式> 和 >
字符,以便我可以将其与存储的数据进行比较。
$codes = array('>','<');
$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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用此函数而不是
str_replace
: http:// /www.php.net/manual/en/function.htmlspecialchars-decode.phpTry this function instead of
str_replace
: http://www.php.net/manual/en/function.htmlspecialchars-decode.php终于发现问题了。与 html 标签无关!问题是(我不知道为什么)jWYSIWYG 在字段末尾添加了大约 24 个空格,因此显然,存储数据和新数据之间的比较结果不同。
我只是这样删除了输入的最后空格:
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: