Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: bb code preg replace
Forum PHP.pl > Forum > Przedszkole
dragoner
  1. $t= mysql_fetch_array(mysql_query("select * from phpbb_posts_text where post_id=".$_GET["post"]));
  2. $tekst=$t["post_text"];
  3.  
  4. function BBCode($tekst)
  5. {
  6. $tekst = nl2br($tekst);
  7. $tekst = htmlspecialchars($tekst);
  8.  
  9. $tekst = preg_replace("#\[b\](.*?)\[/b\]#si",'<b>\\1</b>',$tekst);
  10. $tekst = preg_replace("#\[i\](.*?)\[/i\]#si",'<i>\\1</i>',$tekst);
  11. $tekst = preg_replace("#\[u\](.*?)\[/u\]#si",'<u>\\1</u>',$tekst);
  12. $tekst = preg_replace("#\[s\](.*?)\[/s\]#si",'<s>\\1</s>',$tekst);
  13.  
  14. $tekst = preg_replace("#\[img\](.*?)\[/img\]#si",'<img src="\\1" alt="" />',$tekst);
  15. $tekst = preg_replace("#\[img=(.*?)\](.*?)\[/img\]#si",'<img src="\\1" alt="\\2" />',$tekst);
  16.  
  17. $tekst = preg_replace("#\[color=(.*?)\](.*?)\[/color\]#si",'<font color="\\1">\\2</font>',$tekst);
  18.  
  19. $tekst = preg_replace("#\[url\](http.*?)\[/url\]#si", "<A HREF=\"\\1\">\\1</A>", $tekst);
  20. $tekst = preg_replace("#\[url=(http.*?)\](.*?)\[/url\]#si", "<A HREF=\"\\1\" TARGET=\"_blank\">\\2</A>", $tekst);
  21. $tekst = preg_replace("#\[url\](.*?)\[/url\]#si", "<A HREF=\"http://\\1\">\\1</A>", $tekst);
  22. $tekst = preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<A HREF=\"http://\\1\">\\2</A>", $tekst);
  23.  
  24. $tekst = preg_replace("#\[quote\](.*?)\[/quote\]#si",'<blockquote class="cytat">\\1</blockquote>',$tekst);
  25. $tekst = preg_replace("#\[quote=(.*?)\](.*?)\[/quote\]#si",'<p><cite>\\1</cite> napisał:</p><blockquote>\\2</blockquote>',$tekst);
  26.  
  27. $tekst = preg_replace("#\[code\](.*?)\[/code\]#si",'<pre>\\1</pre>',$tekst);
  28.  
  29.  
  30.  
  31. return($tekst);
  32. }
  33.  
  34.  
  35. echo BBCode();
  36.  
  37.  
  38.  
  39. mysql_close($link);
  40.  
  41. ?>

czemu nie dziala? haha.gif
wookieb
Żałosne. Wiesz co to są argumenty funkcji?
mat-bi
RUFKM?questionmark.gifquestionmark.gif Toż to nie ma prawa zadziałać - przeczytaj jakiś kurs, to się dowiesz!

I na przyszłosć:

  1. ini_set('display_errors', '1');
dragoner
no wlasnie
mam kod
  1. $t= mysql_fetch_array(mysql_query("select * from phpbb_posts_text where post_id=".$_GET["post"]));
  2. echo $t["post_text"];
  3.  
  4.  
  5.  
  6. mysql_close($link);
  7.  
  8. ?>


ktory mi pokazywal post z forum na stronie ale znaczniki bbcode chcial bym zamienic na html

i znalazlem cos takiego

  1. function BBCode($tekst)
  2. {
  3. $tekst = nl2br($tekst);
  4. $tekst = htmlspecialchars($tekst);
  5.  
  6. $tekst = preg_replace("#\[b\](.*?)\[/b\]#si",'<b>\\1</b>',$tekst);
  7. $tekst = preg_replace("#\[i\](.*?)\[/i\]#si",'<i>\\1</i>',$tekst);
  8. $tekst = preg_replace("#\[u\](.*?)\[/u\]#si",'<u>\\1</u>',$tekst);
  9. $tekst = preg_replace("#\[s\](.*?)\[/s\]#si",'<s>\\1</s>',$tekst);
  10.  
  11. $tekst = preg_replace("#\[img\](.*?)\[/img\]#si",'<img src="\\1" alt="" />',$tekst);
  12. $tekst = preg_replace("#\[img=(.*?)\](.*?)\[/img\]#si",'<img src="\\1" alt="\\2" />',$tekst);
  13.  
  14. $tekst = preg_replace("#\[color=(.*?)\](.*?)\[/color\]#si",'<font color="\\1">\\2</font>',$tekst);
  15.  
  16. $tekst = preg_replace("#\[url\](http.*?)\[/url\]#si", "<A HREF=\"\\1\">\\1</A>", $tekst);
  17. $tekst = preg_replace("#\[url=(http.*?)\](.*?)\[/url\]#si", "<A HREF=\"\\1\" TARGET=\"_blank\">\\2</A>", $tekst);
  18. $tekst = preg_replace("#\[url\](.*?)\[/url\]#si", "<A HREF=\"http://\\1\">\\1</A>", $tekst);
  19. $tekst = preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<A HREF=\"http://\\1\">\\2</A>", $tekst);
  20.  
  21. $tekst = preg_replace("#\[quote\](.*?)\[/quote\]#si",'<blockquote class="cytat">\\1</blockquote>',$tekst);
  22. $tekst = preg_replace("#\[quote=(.*?)\](.*?)\[/quote\]#si",'<p><cite>\\1</cite> napisał:</p><blockquote>\\2</blockquote>',$tekst);
  23.  
  24. $tekst = preg_replace("#\[code\](.*?)\[/code\]#si",'<pre>\\1</pre>',$tekst);
  25.  
  26.  
  27.  
  28. return($tekst);
  29. }


i jak to zrobic zeby razem dzialalo?
gothye
  1. echo BBCode($tekst)
wookieb
Wróć do kursu. Nie mamy z tobą o czym rozmawiać.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.