Jump to content


Photo

Solved -- BB Code help


  • Please log in to reply
3 replies to this topic

#1 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 06 August 2006 - 03:27 PM

Sorry for your time I found my error!

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 06 August 2006 - 03:40 PM

i think this has all the corections needed..

<?php

function bbcode($txt)
{
$bbcodes = array( "|\[b\](.+)\[/b\]|is",
                      "|\[u\](.+)\[/u\]|is",
                      "|\[i\](.+)\[/i\]|is",
                      "|\[img\](.+)\[/img\]|is"
);
$replace = array( "<strong>$1</strong>",
                      "<u>$1</u>",
                      "<em>$1</em>",
                      "<img src=\"$1\">"
);

$txt = preg_replace($bbcodes, $replace, $txt);

return nl2br($txt);
}
$texter = strip_tags($_POST[message]);
$str = "$texter";
$str = bbcode($str);
echo $str;
?>

Doesn't give any errors when tested for parse errors and so on..

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 06 August 2006 - 03:40 PM

<?php

function bbcode($txt)
{
$bbcodes = array( "|\[b\](.+)\[/b\]|is",
                      "|\[u\](.+)\[/u\]|is",
                      "|\[i\](.+)\[/i\]|is",
                      "|\[img\](.+)\[/img\]|is"
);
$replace = array( "<strong>$1</strong>",
                      "<u>$1</u>",
                      "<em>$1</em>",
                      "<img src='$1'>"
);

$txt = preg_replace($bbcodes, $replace, $txt);

return nl2br($txt);
}
$texter = strip_tags($_POST[message]);
$str = "$texter";
$str = bbcode($str);
echo $str;
?>

i got 2 errors on line 13. Firstly, you need to either replace with single quotes on escape the inside double quotes on this line:
"<img src="$1">"

I replaced them. Secondly, you were missing a comma at the end of the preceding line.

#4 Chevy

Chevy
  • Members
  • PipPipPip
  • Advanced Member
  • 163 posts

Posted 06 August 2006 - 03:42 PM

Thanks I figured it out :) But thank you a lot!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users