2011-09-23 31 views
-1

可能重复:
Get content between two strings PHP获取标签之间的所有字符串并回显它们?

好吧,这里是我的delima:

这里是我的$内容的例子:

<!--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! 

我怎么能运行一个找到所有“get_all_strings_between()”和ec的函数ho他们在$内容的顶部:

**First Title Here**/**Second Title Here**/**Third Title Here** 

and then my content HERE! 

THANKs !!

回答

2

如果我明白你的问题正确这个正则表达式将做到这一点:

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 

如果我不正确,请提供更多信息什么是这些nextpagenexttitle标签?他们看起来像这样吗?

+0

他们是CMS的一部分..只是在数据库中的字符串。谢谢你的评论。我会试试看! – eberswine

+0

你有它!哇,我研究了这一点,你的是唯一一次为我工作!也许因为我是一个小菜鸟,但非常感谢。这个功能的速度是否快?还是有更快的方式,我有一些$内容字符串是非常大.... ?? – eberswine

+1

正则表达式不是最快的工具,但在实际上遇到问题之前不要考虑性能。尝试运行大字符串,看看会发生什么。 –

相关问题