i wanted to build to my site BBCode functions that my users can use.
Here is the bbcode.php
Code: Select all
<?php
function bbcode($content){ //function starts
$content = nl2br(htmlspecialchars($content)); //writed message
$bbcode = array(
"'\[b\](.*?)\[/b\]'", // Bold
"'\[i\](.*?)\[/i\]'", // Italics
"'\[u\](.*?)\[/u\]'", // Underline
"'\[img\](.*?)\[/img\]'" // Image
);
$html = array( // HTML
"<b>\\1</b>", // Bold
"<i>\\1</i>", // Italics
"<u>\\1</u>", // Underlined
"<img border=\"0\" src=\"\\1\">" // image
);
$content = preg_replace($bbcode, $html, $content); // replaces all BBCode tags with HTML
return nl2br($content);
}
?>Code: Select all
$text = bbcode($text):Code: Select all
$textt = str_replace(array("<br />","<br />","<br />"), array("\n","\r","\r\n"), $text);And when you edit text and upload it again to database, it looks like this:This is test. Something something.
blaah blaah blaah blaah
blaah
And code for text looks like this:This is test. Something something.
blaah blaah blaah blaah
blaah
Code: Select all
This is test. Something something.<br /><br />
<br /><br />
blaah blaah blaah blaah<br /><br /><br /><br />
blaahHope you understand the problem and sorry my bad examples and bad code![/quote]