Posted By

nicolaspar on 03/10/07


Tagged

bbcode b i


Versions (?)

Who likes this?

18 people have marked this snippet as a favorite

maxav
d4rk
Slashman
vali29
Steffen82
silverbux
oso96_2000
coylOne
AlastairDewar
josex
FedericoBiccheddu
Darsain
abdulaziz
Gordy
Net-Freak
Envo
clac
tux-world


PHP - BBcode


 / Published in: PHP
 

Simple bbcode basic replace-

  1. function BBcode($texto){
  2. $a = array(
  3. "/\[i\](.*?)\[\/i\]/is",
  4. "/\[b\](.*?)\[\/b\]/is",
  5. "/\[u\](.*?)\[\/u\]/is",
  6. "/\[img\](.*?)\[\/img\]/is",
  7. "/\[url=(.*?)\](.*?)\[\/url\]/is",
  8. "/\[size=(.*?)\](.*?)\[\/size\]/is",
  9. );
  10. $b = array(
  11. "<i>$1</i>",
  12. "<b>$1</b>",
  13. "<u>$1</u>",
  14. "<img src=\"$1\" />",
  15. "<a href=\"$1\" target=\"_blank\">$2</a>",
  16. '<font size=$1>$2</font>',
  17. );
  18. $texto = preg_replace($a, $b, $texto);
  19. $texto = nl2br($texto);
  20. return $texto;
  21. }
  22.  
  23.  
  24. if(isset($_GET['txt'])) {
  25.  
  26. echo "Has introducido: ".bbcode($_GET['txt']);
  27.  
  28. }

Report this snippet  

You need to login to post a comment.