Php 获取标记之间的所有字符串并回显它们?
可能重复: 好的,这是我的delima: 以下是我的$content示例:Php 获取标记之间的所有字符串并回显它们?,php,Php,可能重复: 好的,这是我的delima: 以下是我的$content示例: <!--nextpage-->First Title Here<!--nexttitle--> some more text here and here and here and here a little more here! <!--nextpage-->Second Title Here<!--nexttitle--> some more text her
<!--nextpage-->First Title Here<!--nexttitle-->
some more text here
and here and here and here
a little more here!
<!--nextpage-->Second Title Here<!--nexttitle-->
some more text here
and here and here and here
a little more here!
<!--nextpage-->Third Title Here<!--nexttitle-->
some more text here
and here and here and here
a little more here!
谢谢 如果我正确理解了你的问题,这个regexp可以:
function get_all_strings_between($content) {
preg_match_all('/<!--nextpage-->([^<]*)<!--nexttitle-->/', $content, $m);
return implode(' / ', $m[1]);
}
// then you echo get_all_strings_between($content) where you need it
如果我不正确,请提供更多信息这些下一页和下一页标签是什么?他们看起来像这样吗?他们是CMS的一部分。。只是数据库中的字符串。谢谢你的评论。我会试试看!!你明白了!!哇,我研究了这个,你的是唯一一次对我有用!!也许是因为我是个笨蛋,但非常感谢。此功能的速度快吗??或者有没有更快的方法,我的一些$content字符串非常大……?regexp不是最快的工具,但在实际遇到问题之前不要考虑性能。尝试对大字符串运行它,看看会发生什么。
function get_all_strings_between($content) {
preg_match_all('/<!--nextpage-->([^<]*)<!--nexttitle-->/', $content, $m);
return implode(' / ', $m[1]);
}
// then you echo get_all_strings_between($content) where you need it