Chat LIVE With Programming Experts! There Are 23 Online Right Now...

 

Code Snippets

  

PHP Source Code


Welcome to Dream.In.Code
Become a PHP Expert!

Join 244,141 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,345 people online right now. Registration is fast and FREE... Join Now!





Simple BBCode Parser

this snippet allows you to easily add/remove BBCode functionality, and can easily be called

Submitted By: JBrace1990
Actions:
Rating:
Views: 609

Language: PHP

Last Modified: June 8, 2008
Instructions: To use this snippet, all you need to do is add it into the beginning of your PHP file, and then call it through bb() around the text you wish to check

Snippet


  1. <?php
  2. function bb($text)
  3. { //start the function
  4. $array=array(  //creates an array which allows you to add/edit BBCode functionality
  5. "[b]" => "<strong>"
  6. "[/b]" => "</strong>"
  7. "[i]" => "<em>"
  8. "[/i]" => "</em>"
  9. "[u]" => "<u>"
  10. "[/u]" => "</u>"
  11. "[center]" => "<div align=center>",
  12. "[/center]" => "</div>",
  13. "[big]" => "<h1>",
  14. "[/big]" => "</h1>",
  15. "[nl]" => "<br>",
  16. // to add more, simply enter them in a "$tag" => "$replacement_tag",  format
  17. );
  18. $newtext = str_replace(array_keys($array), array_values($array), $text); //this replaces the array key (left side) with their respective values (right side)
  19. return $newtext;
  20. }
  21. ?>

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month