views:

45

answers:

5

I have a chunk of text like:

<b>First content</b> followed by <b>second content</b>

OR

"First content" and then "second content"

And I want to create an array that looks: [1] => "First content" [2] => "second content"

From either example, where I get the content between two tags. I've figured out how to get the first instances, but can't figure out the best way to make it recursive.

+2  A: 

If you are looking to extract all content between specific tags, you may be best off with a HTML DOM Parser like simplehtmldom.

Pekka
+2  A: 

If you know what exactly is between "First content" and "second content", use explode:

http://php.net/manual/en/function.explode.php

e.g.

$values = explode("followed by", $yourtext);

(use "strip_tags" on your array-elements if you just want the plaintext)

Select0r
I wound up using explode , but using my tags (<b> or " in the above example), and then logically figuring out which ones were contained in the tags. Thanks!
Corey Maass
A: 
<?php

$yourArray = split(" followed by ", $yourString);

?>

As long as you have the same text in between each value that you want to brake up into an array you can use this example.

Keith Maurino
A: 
$string="<b>First content</b> followed by <b>second content</b>";
$s = explode("followed by", strip_tags($string));
print_r($s);
ghostdog74
+1  A: 

basically you need a regexp in form "START(.+?)END", for example

$a = "<b>First content</b> followed by <b>second content</b>";
preg_match_all("~<b>(.+?)</b>~", $a, $m);
print_r($m[1]);
stereofrog