使用正则表达式:
$str = '<p style="color:red;"><b>asd</b>para<img src="afs"/>graph 1</p >
<p>paragraph 2</p>
<p>paragraph 3</p>
<p>paragraph 4</p>
';
// preg_match_all('/<p.*>([^\<]+)<\/p\s*>/i',$str,$matches);
//for inside html like a comment sais:
preg_match_all('/<p[^\>]*>(.*)<\/p\s*>/i',$str,$matches);
print_r($matches);
印刷:
Array
(
[0] => Array
(
[0] => <p style="color:red;"><b>asd</b>para<img src="afs"/>graph 1</p >
[1] => <p>paragraph 2</p>
[2] => <p>paragraph 3</p>
[3] => <p>paragraph 4</p>
)
[1] => Array
(
[0] => <b>asd</b>para<img src="afs"/>graph 1
[1] => paragraph 2
[2] => paragraph 3
[3] => paragraph 4
)
)