Jump to content

[SOLVED] Regular Expression Image without anchor around it


aragon1337

Recommended Posts

The following regular expression matches an image tags with anchor around it,

 

preg_match_all ('/((?:<\s*a\s*(?:.*)\s*>)<\s*img\s*(?:.*)\s*\/>(?:<\/\s*a\s*>))/i', $news_text, $pattern1, PREG_PATTERN_ORDER);

 

Now i want another expression that matches ONLY the image tags that DOES NOT have anchor tag around it.

 

For example the following are stored in a variable,

 

$str = '<img src="hello.jpg" title="sadsad" />

<a href="one.html"><img src="hi.jpg" title="asdat" /></a>'

 

I want to match ONLY <img src="hello.jpg" title="sadsad" /> not the other.

 

Please help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.