& 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:
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
Reply to discussion (solution)
Match first. Then assemble the result.
$ S = <TXT
News 1 |
2014-03-12 |
News 2 |
2014-02-20 |
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;
It is better to use str_replace.
Match first. Then assemble the result.
$ S = <TXT
News 1 |
2014-03-12 |
News 2 |
2014-02-20 |
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;
Thank you very much for your answers.
After testing, the results are indeed effective.
However, I also want the hyperlink to have a specific address, such:
preg_match_all('#
]+>\s*]+>(.+?)\s*
]+>(.+?)<#s',$s,$m);$html="
\n";foreach($m[1] as $k=>$v) $html .= "
- {$m[2][$k]} {$m[3][$k]}
\n";$html .= '
';echo $html;
The moderator is very powerful ~~~
Like ~
Close the post.