EchoFool Posted February 17, 2008 Share Posted February 17, 2008 I have a function for bbcode but when i echo the function it comes out blank! Not sure what i did wrong... This is my code: <?php $Message = '[b] Bold [/b] not bold.'; function BBCode($BB){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>"); $Message = str_replace(array_keys($BBCode), array_values($BBCode), $Message); return $Message; } Echo $BB; ?> Could some one test this tell me if it works for me cos when i echo $BB nothing happens. Quote Link to comment Share on other sites More sharing options...
trq Posted February 17, 2008 Share Posted February 17, 2008 $BB does not exists outside your function. Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 17, 2008 Author Share Posted February 17, 2008 So i have echo $Message? Because i tried that also, and all i got was the text but not <b> tags around it when i looked at the page source to check. Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 17, 2008 Share Posted February 17, 2008 $newString = BBCode($Message); echo $newString; Try that Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 17, 2008 Author Share Posted February 17, 2008 $newString = BBCode($Message); echo $newString; Try that Ok that didn't echo anything .. but i don't get the undefined variable error, so it must be there but won't display im guessing? My current code: <?php function BBCode($BB){ $BBCode = array("&" => "&", "<" => "<", ">" => ">", "[b]" => "<b>", "[/b]" => "</b>", "[i]" => "<i>", "[/i]" => "</i>", "[u]" => "<u>", "[/u]" => "</u>", "[img]" => "<img src='", "[/img]" => "'>"); $Message = str_replace(array_keys($BBCode), array_values($BBCode), $Message); return $Message; } $newString = BBCode($Message); echo $newString;?> Quote Link to comment Share on other sites More sharing options...
PHP Monkeh Posted February 17, 2008 Share Posted February 17, 2008 Change $Message = str_replace(array_keys($BBCode), array_values($BBCode), $Message); return $Message; to $Message = str_replace(array_keys($BBCode), array_values($BBCode), $BB); return $Message; Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 17, 2008 Author Share Posted February 17, 2008 Ok it now echo's but it won't put the tags around it.. this is my page source of the echo: <tr> <td colspan="2" valign="top" bgcolor="#ecfff7"><br> Bold not bold. </td> </tr> Notice there is no <b> </b> Quote Link to comment Share on other sites More sharing options...
EchoFool Posted February 17, 2008 Author Share Posted February 17, 2008 Wait its working now! Thanks alot guys ! [sOLVED] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.