Home > Backend Development > PHP Tutorial > 求解 关于替换和smarty的几个小问题

求解 关于替换和smarty的几个小问题

WBOY
Release: 2016-06-13 13:33:08
Original
866 people have browsed it

求解 关于替换和smarty的几个问题
1 关于替换
for ($i=0;$i $res1 = $res[$i];
$res1['content'] = preg_replace("/($selkey)/is","\\0",$res1['content']);
$res1['content'] = stristr($res1['content'],$selkey);
$res2[] = $res1;
/*echo "

";<br>	print_r($res1);<br>	echo "
Copy after login
";
exit();*/

问题:这段函数显示的内容正常的,是$selkey从content中第一次出现到最后的内容,但是为什么第一个$selkey没有被preg_replace的样式修饰? 而当我把preg_replace函数和stristr函数位置互换之后,结果又正确了?

2 关于smarty中的truncate函数
用truncate处理上面的代码出来的结果,被preg_replace修饰的所有样式都没了,我试了试加了个超链接,结果也不行,去掉这个函数后,又正常了,这是怎么回事?(因为smarty的truncate对中文支持不好,我使用的是从网上下载的修改过的truncate,会不会是这个原因?如果是又该怎么解决?)

------解决方案--------------------
str_ireplace() 就能满足你的要求
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template