Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Closed TopicStart new topic
> bb code preg replace
dragoner
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 28.05.2011

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


  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

Ten post edytował dragoner 28.05.2011, 15:01:14
Go to the top of the page
+Quote Post
wookieb
post
Post #2





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Żałosne. Wiesz co to są argumenty funkcji?


--------------------
Go to the top of the page
+Quote Post
mat-bi
post
Post #3





Grupa: Zarejestrowani
Postów: 690
Pomógł: 92
Dołączył: 6.02.2011

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


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');
Go to the top of the page
+Quote Post
dragoner
post
Post #4





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 28.05.2011

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


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?
Go to the top of the page
+Quote Post
gothye
post
Post #5





Grupa: Zarejestrowani
Postów: 702
Pomógł: 65
Dołączył: 16.03.2009

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


  1. echo BBCode($tekst)


--------------------
Nie udzielam pomocy poprzez PW
Go to the top of the page
+Quote Post
wookieb
post
Post #6





Grupa: Moderatorzy
Postów: 8 989
Pomógł: 1550
Dołączył: 8.08.2008
Skąd: Słupsk/Gdańsk




Wróć do kursu. Nie mamy z tobą o czym rozmawiać.


--------------------
Go to the top of the page
+Quote Post

Closed TopicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 08:36