Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

JeremysFilms
Sunday, July 23rd, 2006 at 3:07:15pm UTC 

  1. Here's how I make my own "bbcode" and use it.
  2.  
  3. 1) Run htmlentities() on the message being posted to make it safe before it's added to a database.
  4. 2) Insert this message that has been altered with htmlentities() into the database.
  5. 3) When you are outputting the messages to the page, that's when you want to run something to replace the bbcode with html, this way, if you ever want to alter what a specific tag does, you won't have to go through every post and change the html there, since it'll just have the bbcode in there.
  6.  
  7. Just use a preg_replace to replace the bbcode with html during output, it's pretty simple:
  8. __________________________________________________
  9. $pattern=array(
  10. '/\[b\](.*)\[\/b\]/i',
  11. '/\[i\](.*)\[\/i\]/i',
  12. '/\[u\](.*)\[\/u\]/i',
  13. '/\[color=(.*)\](.*)\[\/color\]/i'
  14. );
  15.  
  16. $replace=array(
  17. '<b>\\1</b>',
  18. '<i>\\1</i>',
  19. '<u>\\1</u>',
  20. '<font color=\"\\1\">\\2</font>'
  21. );
  22.  
  23. preg_replace($pattern,$replace,$stringToOutput);
  24. __________________________________________________
  25.  
  26. $stringToOutput would be the string that is being outputted from the database.
  27. Example snippet:
  28.  
  29. while($row = mysql_fetch_array($result)){
  30. echo preg_replace($pattern,$replace,stripslashes($row['message'])).'<br /><br />;
  31. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right
worth-right