简体   繁体   English

str_replace无法在html代码中工作

[英]str_replace not working in html codes

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. 我正在使用其中一个字段的表单是RTF textarea(jWYSIWYG),它在页面加载时自动填充了一些数据库信息,所有这些都使用Symfony框架。 This RTF editor can add some html tags like <p> , <b> , etc. 这个RTF编辑器可以添加一些html标签,如<p><b>等。

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 &lt;p&gt; 当我在发送表单之前尝试知道textarea是否已经被修改时,麻烦就开始了:我从$request获得的是所有的html标签都被编码为&lt;p&gt; , &lt;b&gt; &lt;b&gt; , etc. I tryed to replace that expressions with the < and > characters so i can compare it to the stored data. 我尝试用<>字符替换表达式,以便我可以将它与存储的数据进行比较。

$codes = array('&gt;','&lt;');
$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. 但是这个函数返回了我作为str_replace函数的参数传递的相同数组。 What am I doing wrong? 我究竟做错了什么? have anyone had the same problem? 有谁有同样的问题?

尝试使用此函数而不是str_replacehttpstr_replace

Finally discovered the problem. 终于发现了这个问题。 Was not about the html tags! 不是关于HTML标签! 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. 问题是(我不知道为什么)jWYSIWYG在字段的末尾增加了大约24个空格,所以很明显,存储数据和新数据之间的比较结果不同。

i simply deleted the final whitespaces of the input this way: 我只是以这种方式删除了输入的最后一个空格:

$text = rtrim($text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM