I made a custom bbcode parser function and added it on my helper
if ( !function_exists('bbcode_parser'))
{
function bbcode_parser($str)
{
$patterns = array(
'#\[b\](.*?)\[/b\]#is',
'#\[img\](.*?)\[/img\]#is',
'#\[url\](.*?)\[/url\]#is',
'#\[url=(.*?)\](.*?)\[/url\]#is'
);
$replacements = array(
'<strong>$1</strong>',
'<img src="$1" />',
'<a href="$1">$1</a>',
'<a href="$1">$2</a>',
);
$str = preg_replace($patterns, $replacements, $str);
return $str;
}
}
It's good and works like I want it to but my question is how to apply a function on each replacement value.
fe. for the url that doesn't have inner data, i want to replace with the website title of the url
or validate the url if it has http://
i would also like to check the size of the image, if it's too large, i want to resize it when printed by adding a "width" attribute and then just add an tag to the full size image.
is this possible? if so, how to do this?