开发者

Get All Strings between tags and echo them? [duplicate]

开发者 https://www.devze.com 2023-04-06 20:17 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Get content between two strings PHP
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Get content between two strings PHP

Ok, here is my delima:

here is an example of my $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-->Th开发者_如何学Pythonird Title Here<!--nexttitle-->

some more text here

and here and here and here

a little more here!

How could I run a function that finds all "get_all_strings_between()" and echo them at the top of the $content:

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

and then my content HERE!

THanks!!


If I understood your question correctly this regexp will do it:

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

If I'm incorrect, please provide more info what are these nextpage and nexttitle tags? Are they appear like this literally?

0

精彩评论

暂无评论...
验证码 换一张
取 消