在标签之间获取所有字符串并回显它们?

时间:2011-09-23 16:23:23

标签: php

  

可能重复:
  Get content between two strings 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 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()”的函数,并在$ content的顶部回显它们:

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

and then my content HERE!

谢谢!

1 个答案:

答案 0 :(得分: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代码是什么?它们看起来像字面意思吗?