- preg_match: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$content = 'foo bar baz <img src="http://ak-hdl.buzzfed.com/static/2014-06/6/12/enhanced/webdr08/enhanced-21313-1402070821-11.jpg" width="500" height="1000"/> dragons and ponies.';
for ( $i = 0; $i < 1000; $i++ )
{
if ( preg_match_all( '#<(?P<tag>img)[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) )
{
foreach ( $matches[0] as $match )
{
preg_match( '/ src="([^"]+)"/', $content, $src );
preg_match( '/ width="([0-9]+)"/', $content, $width );
preg_match( '/ height="([0-9]+)"/', $content, $height );
}
}
}