Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] BBCode
Reiven
post 5.10.2009, 11:51:16
Post #1





Grupa: Zarejestrowani
Postów: 100
Pomógł: 1
Dołączył: 17.03.2006

Ostrzeżenie: (0%)
-----


Witam,
zacząłem robić sobie własne bbcode, lecz mam problem przy znaczniku
  1. [/PHP]
  2.  
  3. [php]<?PHP
  4. function BBCode($tekst){
  5. // $tekst = nl2br($tekst);
  6. $tekst = htmlspecialchars($tekst);
  7. $tekst = preg_replace("#\[b\](.*?)\[/b\]#si",'<b>\\1</b>',$tekst);
  8. $tekst = preg_replace("#\[i\](.*?)\[/i\]#si",'<i>\\1</i>',$tekst);
  9. $tekst = preg_replace("#\[u\](.*?)\[/u\]#si",'<u>\\1</u>',$tekst);
  10. $tekst = preg_replace("#\[s\](.*?)\[/s\]#si",'<s>\\1</s>',$tekst);
  11. $tekst = preg_replace("#\[img\](.*?)\[/img\]#si",'<img src="\\1" alt="" />',$tekst);
  12. $tekst = preg_replace("#\[url\](.*?)\[/url\]#si", "<A HREF=\"http://\\1\">\\1</A>", $tekst);
  13. $tekst = preg_replace("#\[url=(.*?)\](.*?)\[/url\]#si", "<A HREF=\"http://\\1\">\\2</A>", $tekst);
  14. $tekst = preg_replace("#\[quote\](.*?)\[/quote\]#si",'<blockquote class="cytat">\\1</blockquote>',$tekst);
  15. $tekst = preg_replace("#\[code\](.*?)\[/code\]#si",'<pre>\\1</pre>',$tekst);
  16. $tekst = preg_replace("#\[php\](.*?)\[/php\]#si", highlight_string('\\1', true),$tekst);
  17. return nl2br($tekst);
  18.  
  19. }
  20.  
  21. $s = "[php ]<?PHP echo 'test'; ?>[/php ]";
  22. echo BBCode($s);
  23.  
  24. #echo highlight_string(stripslashes("$s"), true);
  25.  
  26. ?>


nie chce mi to pokolorować składni :|
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 01:58