The Little Guy Posted February 13, 2007 Share Posted February 13, 2007 I can not get this function to work: function bbcode2html($strInput) { return preg_replace('/\\[php\\]/i', '/\\[\/php\\]/i',highlight_string($strInput),$strInput); } It highlights the correct string, but it doesn't remove the bbcode tags, and it adds 1 to the end of every string. I don't know what is wrong. Link to comment https://forums.phpfreaks.com/topic/38389-php-bbcode/ Share on other sites More sharing options...
fert Posted February 13, 2007 Share Posted February 13, 2007 I don't think you need to escape the \'s Link to comment https://forums.phpfreaks.com/topic/38389-php-bbcode/#findComment-184079 Share on other sites More sharing options...
The Little Guy Posted February 14, 2007 Author Share Posted February 14, 2007 I just copied the code from wikepedia.com, replaced things. I turned the \\ into \ and it didn't have any effect. Link to comment https://forums.phpfreaks.com/topic/38389-php-bbcode/#findComment-184084 Share on other sites More sharing options...
fert Posted February 14, 2007 Share Posted February 14, 2007 try this function bbcode2html($strInput) { return preg_replace("/\[php\](.*?)[\/php\]/",highlight_string($strInput),$strInput); } Link to comment https://forums.phpfreaks.com/topic/38389-php-bbcode/#findComment-184088 Share on other sites More sharing options...
The Little Guy Posted February 14, 2007 Author Share Posted February 14, 2007 you were forgetting a \ but I added, and now all that happens is it duplicates the line. one in <code> tags, and one as plain text. Link to comment https://forums.phpfreaks.com/topic/38389-php-bbcode/#findComment-184094 Share on other sites More sharing options...
The Little Guy Posted February 14, 2007 Author Share Posted February 14, 2007 This works: <?php function bbcode($s) { $s = str_replace("]\n", "]", $s); $match = array('#\[php\](.*?)\[\/php\]#se'); $replace = array("'<div>'.highlight_string(stripslashes('$1'), true).'</div>'"); return preg_replace($match, $replace, $s); } ?> Link to comment https://forums.phpfreaks.com/topic/38389-php-bbcode/#findComment-184220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.