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. Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/ Share on other sites More sharing options...
trq Posted February 17, 2008 Share Posted February 17, 2008 $BB does not exists outside your function. Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468888 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. Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468892 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 Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468893 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;?> Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468895 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; Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468897 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> Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468898 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] Link to comment https://forums.phpfreaks.com/topic/91539-function-is-not-working-help-please/#findComment-468900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.