- 论坛徽章:
- 0
|
本帖最后由 bzdghdn 于 2010-04-09 12:34 编辑
有一个!USpecial Live!U02/14 SAK. <br />loves "DOT" St. Valentine's Day Live !!! 这样的字符串。它是用一个自定义标签直接从其它的地方读出来的,也就是说我无法对其中的单引号和双引号转义,反正读出来就是这个值。现在我需要把其中的<br/>去掉,结果遇到了问题。 这个系统的情况是它先用了一个模版系统把模版文件转成php文件,然后再把这个php解释执行。
模版文件中<$MTEntryTitle$>这个标签就是代表上面红色的字符串。
模版文件 - str_replace(array('<br />', '<br/>','<br>'), "", <$MTEntryTitle$>)
复制代码 对应php- str_replace(array(array('<br />', '<br/>','<br>'), "", !USpecial Live!U02/14 SAK. <br />loves "DOT" St. Valentine's Day Live !!!)
复制代码 失败,因为php中定义的字符串要用'或"包含起来
模版文件- str_replace(array('<br />', '<br/>','<br>'), "", '<$MTEntryTitle$>')
复制代码 对应php- str_replace(array(array('<br />', '<br/>','<br>'), "",'!USpecial Live!U02/14 SAK. <br />loves "DOT" St. Valentine's Day Live !!!')
复制代码 失败,因为字符串中含有一个单引号
模版文件- str_replace(array('<br />', '<br/>','<br>'), "", "<$MTEntryTitle$>")
复制代码 对应php- str_replace(array(array('<br />', '<br/>','<br>'), "","!USpecial Live!U02/14 SAK. <br />loves "DOT" St. Valentine's Day Live !!!")
复制代码 失败,因为中含有双引号
模版文件
- $title = << HTML;
- <$MTEntryTitle$>
- HTML;
- str_replace(array('<br />', '<br/>','<br>'), "", $title)
复制代码 对应php- str_replace(array(array('<br />', '<br/>','<br>'), "",'!USpecial Live!U02/14 SAK. <br />loves "DOT" St. Valentine's Day Live !!!')
复制代码 失败,php自动用单引号包含起来
现在的问题是,如果我要处理这个字符串,首先要把它作为参数传给某个字符串处理函数。但是不管我用单引号还是双引号把它包含起来,都会出错。 |
|