Hey, I'm making a little news system and the last thing I need to do is include the BBCode. I read that I could use str_replace to do this? How would I set about doing it?![]()

Hey, I'm making a little news system and the last thing I need to do is include the BBCode. I read that I could use str_replace to do this? How would I set about doing it?![]()
Back for a while.
http://w3schools.com/php/func_string_str_replace.asp
If I was you, i'd just insert the original data into the database, then convert it when displaying it. I'm not sure if converting it then inputting would be quicker, I imagine so, but meh.
This is our situation and we're happy to be here,
I wouldn't change this place for anything.
You would need to use preg_replace otherwise someone could do [b] and leave it open and the rest of the page would be in bold.http://w3schools.com/php/func_string_str_replace.asp
If I was you, i'd just insert the original data into the database, then convert it when displaying it. I'm not sure if converting it then inputting would be quicker, I imagine so, but meh.
That may not be 100% right but give it a go.PHP Code:$string = "[b]This[/b] text is in [b]bold[/b]";
preg_replace("/[b](.*?)[/b]/", "<b>$1</b>", $string);
Lets set the stage on fire, and hollywood will be jealous.
Yeah I was thinking that way but I just wanted to say include the file onto the index page so when say.. <b>Hiya</b> is displayed it automatically changes it to bold.
Back for a while.
You can make a quick function like this:
Code:function bbcode($content) { $content = preg_replace(”\[b\](.+?)\[\/b\]”, “<b>$1</b>”, $content); $content = preg_replace(”\[i\](.+?)\[\/i\]”, “<i>$1</i>”, $content); $content = preg_replace(”\[u\](.+?)\[\/u\]”, “<u>$1</u>”, $content); $content = preg_replace(”\[img\](.+?)\[\/img\]”, “<img src=\”$1\” alt=\”\” />”, $content); return($content); }
Last edited by DUB; 26-09-2008 at 08:35 PM.
;veni vidi vici
;i came, i saw, i ownt
I get this when doing DUB's method.
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\User system revision\functions.php on line 64
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\User system revision\functions.php on line 65
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\User system revision\functions.php on line 66
Warning: preg_replace() [function.preg-replace]: Delimiter must not be alphanumeric or backslash in C:\wamp\www\User system revision\functions.php on line 67
This is our situation and we're happy to be here,
I wouldn't change this place for anything.
oh yeah my bad
PHP Code:function bbcode($content)
{
$content = preg_replace(”/[b\](.+?)/[\/b\]”, “<b>$1</b>”, $content);
$content = preg_replace(”/[i\](.+?)/[\/i\]”, “<i>$1</i>”, $content);
$content = preg_replace(”/[u\](.+?)/[\/u\]”, “<u>$1</u>”, $content);
$content = preg_replace(”/[img\](.+?)/[\/img\]”, “<img src=\”$1\” alt=\”\” />”, $content);
return($content);
}
;veni vidi vici
;i came, i saw, i ownt
Parse error: syntax error, unexpected '=', expecting ')' in /home/luke/public_html/syst/bbcode.php on line 5oh yeah my bad
PHP Code:function bbcode($content)
{
$content = preg_replace(”/[b\](.+?)/[\/b\]”, “<b>$1</b>”, $content);
$content = preg_replace(”/[i\](.+?)/[\/i\]”, “<i>$1</i>”, $content);
$content = preg_replace(”/[u\](.+?)/[\/u\]”, “<u>$1</u>”, $content);
$content = preg_replace(”/[img\](.+?)/[\/img\]”, “<img src=\”$1\” alt=\”\” />”, $content);
return($content);
}
Back for a while.
oh crap
that should workPHP Code:function bbcode($content)
{
$content = preg_replace('/\[b\](.*?)\[\/b\]/is', '<strong>$1</strong>', $content);
$content = preg_replace('/\[i\](.*?)\[\/i\]/is', '<em>$1</em>', $content);
$content = preg_replace('/\[u\](.*?)\[\/u\]/is', '<u>$1</u>', $content);
$content = preg_replace('/\[img\](.*?)\[\/img\]/is',
'<img src="$1" />', $content);
return($content);
}
;veni vidi vici
;i came, i saw, i ownt
Doesn't work when I apply the <strong></strong> tags.
Back for a while.
Want to hide these adverts? Register an account for free!