Solve several questions about replace and smarty 1 about replace for ($ I = 0; $ I & lt; $ res_length; $ I ++) {$ res1 = $ res [$ I]; $ res1 ['content'] = preg_replace (& quot;/($ selkey)/is & quot;, & quot; & lt; fontcolo solves several questions about replacement and smarty
1. about replacement
For ($ I = 0; $ I <$ res_length; $ I ++ ){
$ Res1 = $ res [$ I];
$ Res1 ['content'] = preg_replace ("/($ selkey)/is ","
\ 0", $ Res1 ['content']);
$ Res1 ['content'] = stristr ($ res1 ['content'], $ selkey );
$ Res2 [] = $ res1;
/* Echo"
";
Print_r ($ res1 );
Echo"
";
Exit ();*/
Q: the content displayed in this function is normal. it is the first time that $ selkey appears from the content to the final content. why is the first $ selkey not modified by the preg_replace style? After I swap the positions of the preg_replace and stristr functions, the result is correct?
2. about the truncate function in smarty
Use truncate to process the results of the above code. all the styles modified by preg_replace are gone. I tried to add a hyperlink and the results won't work either. after removing this function, it's normal again. what's going on? (Because the truncate of smarty has poor support for Chinese characters, is it because I downloaded the modified truncate from the internet? If so, how can this problem be solved ?)
------ Solution --------------------
Str_ireplace () can meet your requirements.