I have a piece of html like this:
<p>some text</p>
<p>more text</p>
I want to take out the text only and put it into an array. The easiest way seemed to be using explode like this:
$text_chunks = explode(‘<p>’, $html_string); // forgetting the trailing </p> // at this stage
This doesn’t work even when I escape the tags. Any ideas?
strip_tags(); ?
then you could perhaps do something like explode("
\r", $text_chunks); if it’s spaced like that anyway.
There would be a better way to do it using regex though. 
N9ne
3
Are you sure it doesn’t work?
Try print_r($text_chunks);
seanf
4
You could do this:
<?php
echo '<pre>';
$str = '<p>some text</p>
<p>more text</p>';
preg_match_all ( '#<p>(.+?)</p>#', $str, $parts );
print_r ( $parts[1] );
echo '</pre>';
?>
Sean 
beat you all. 
(use seans method ;))
Thanks. I managed it like this as well:
$text_chunks = preg_split(‘{<p>}’, $html_string);
$chunk = ereg_replace(‘\<\/p\>’, ‘’, $text_chunks[1]); //or whichever chunk I
//want
But i still can’t understand why explode doesn’t work?
Jump
7
You should use preg_replace instead.
Jump
8
Or better yet.
$chunk = strip_tags($text_chunks[1]);