& Lt; tr & gt; & lt; td & gt; test & lt;/td & gt; & lt; tr & gt; replace it with & lt; LI & gt; test & lt;/LI & gt; for PHP regular expression Replacement. thank you. Example: & lt; tr & gt; & lt; td & gt; test & lt;/td & gt; & lt; tr & gt; replace it with & lt; LI & gt; test & lt;/LI & gTestTo replace
TestPlease replace the PHP regular expression. thank you.
Example:
TestTo replace
TestPlease replace the PHP regular expression. thank you.
Because my HTML code is as follows:
News 1
2014-03-12
News 2
2014-02-20
To replace
News 1 2014-03-12
News 2 2014-02-20
------ Solution --------------------
Match first. Then assemble the result.
$ S = <TXT
News 1
2014-03-12
News 2
2014-02-
TXT;
Preg_match_all ('#
] +> \ S *] +> (. + ?)\ S *
] +> (. + ?) <# S ', $ s, $ m );
$ Html ="
\ N ";
Foreach ($ m [1] as $ k => $ v) $ html. ="
$ V {$ m [2] [$ k]}\ N ";
$ Html. ='';
Echo $ html;
------ Solution --------------------
It is better to use str_replace.