Jump to content

Parse BBCode URL's


wrathican

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.