hi. I have a little problem. I'm trying to parse data from a site and I need some help. I have a simililar html structure <div>some content</div> Code (markup): and <div><p>some content</p></div> Code (markup): What is the pattern so i can grabb some content if sometimes is between <p> tag and sometimes is not Thx
$c = "<div>some content</div>"; $c .= "<div><p>some content</p></div>"; preg_match_all( '/<div>(?:<p>)?(.*?)(?:<\/p>)?<\/div>/ims', $c, $m); print_r($m[1]); PHP: Will output: Array ( [0] => some content [1] => some content )