I'm trying to create a code similar to BBCode. I found the function on the web and now need to add in php tags.
Here is my code
<?php
function bbcode($messagetext) {
$search = array('#<a href="http://([a-z]+?://){1}(.*?)\" target="_blank">([a-z]+?://){1}(.*?)</a>#', '#[url](.*?)[/url]#', '#<a href="http://([a-z" target="_blank">+?://){1}(.*?)](.*?)</a>#', '#(.*?)#', '#(.*?)#', '#(.*?)#', '#[img]([a-z]+?://){1}(.*?)[/img]#', '#[img](.*?)[/img]#', '#[phptag](.*?)[/phptag]#');
$replace = array('<a href="12">$1$2</a>', '<a href=http://12>1</a>', '<a href="12">3</a>', '<b>1</b>', '<i>1</i>', '<u>1</u>', '<img src="12">', '<img src="12" />', highlight_string('1') );
$messagetext = preg_replace($search, $replace, $messagetext);
return $messagetext;
}
print nl2br(bbcode($myText));
?>
For some reason it doesn't print anything out if I include the <?php or <? and if I end it with ?> it doesn't print anything. Where am I going wrong.
Also the text that is within the php tags should then use the function highlight_string but I can't get this to work either.
Thank you