wrathican Posted August 13, 2008 Share Posted August 13, 2008 hey people, im in the process of making a small CMS and im making my own bbcode type thing. im only having a few bbcodes and i have them all sorted apart from the link one im going to use [ url = blahhhhh ] link [ / url ] without the spaces but i cant figure out how to parse it so it looks like a html link <a href="blahhhh">link</a> help? Thanks Link to comment https://forums.phpfreaks.com/topic/119455-parse-bbcode-urls/ Share on other sites More sharing options...
!jazz Posted August 13, 2008 Share Posted August 13, 2008 hey people, im in the process of making a small CMS and im making my own bbcode type thing. im only having a few bbcodes and i have them all sorted apart from the link one im going to use [ url = blahhhhh ] link [ / url ] without the spaces but i cant figure out how to parse it so it looks like a html link <a href="blahhhh">link</a> help? Thanks Try this class. It is very powerful and extensible! http://www.christian-seiler.de/projekte/php/bbcode/index_en.html JaZz Link to comment https://forums.phpfreaks.com/topic/119455-parse-bbcode-urls/#findComment-615362 Share on other sites More sharing options...
thebadbad Posted August 13, 2008 Share Posted August 13, 2008 This simple preg_replace should work: <?php function bb2html($text) { $find = array( '~\[url=(.*?)\](.*?)\[/url\]~s' ); $replace = array( '<a href="$1">$2</a>' ); return preg_replace($find, $replace, $text); } //usage $text = 'a bb code link: [url=http://google.com/]Google[/url]'; echo bb2html($text); ?> Link to comment https://forums.phpfreaks.com/topic/119455-parse-bbcode-urls/#findComment-615408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.