Convert inline image tags like [image:123:title:size] into HTML img tags
- by Jacques Joubert
I am looking for help with regular expression $pattern to convert inline image tags like [image:123:title:size] into HTML img tags.
here is the code:
//[image:ID:caption:size]
$content = '[image:38:title:800x900]';
preg_match_all( '/\[image:(\d+)(:?)([^\]]*)\]/i', $content, $images );
if( !empty( $images[0] ) )
{ // There are image inline tags in the content
foreach( $images[0] as $i => $tag )
{
$link_ID = (int)$images[1][$i];
$caption = empty( $images[2][$i] ) ? '#' : $images[3][$i];
$size = empty( $images[4][$i] ) ? '#' : $images[4][$i];
}
echo '<br />';
echo 'ID: '.$link_ID.'<br />';
echo 'Tag: '.$caption.'<br />';
echo 'size: '.$size.'<br />';
}
which outputs:
ID: 12
Tag: caption:size
size: #
Any help would be great!