Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [bbcode] problem z [quote]
quex
post 25.09.2005, 09:31:24
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 11.02.2004

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


Skrypt przedstawia się tak:
  1. <?php
  2.  
  3. // Funkcja zamieniająca tagi [quote]tekst[/quote]
  4. function bbcode_QuoteNoAutor($string){
  5. $new_string ='<div class="quote">'.$string[1].'</div>';
  6. return $new_string;
  7. }
  8. // Funkcja zamieniająca tagi [quote=autor]tekst[/quote]
  9. function bbcode_QuoteAutor($string){
  10. $new_string = '<div class="header">'.$string[1].' napisał/a:</div>';
  11. $new_string.='<div class="quote">'.$string[2].'</div>';
  12. return $new_string;
  13. }
  14. function bbcode($text){
  15. $text = preg_replace_callback("#[img](.*?)[/img]#si", "bbcode_ImgNoAlt", $text);
  16. $text = preg_replace_callback("#[img=(.*?)](.*?)[/img]#si", "bbcode_ImgAlt", $text);
  17. $text = preg_replace_callback("#(.*?)#si", "bbcode_UrlNoName", $text);
  18. $text = preg_replace_callback("#(.*?)#si", "bbcode_UrlName", $text);
  19. $text = preg_replace_callback("#[quote](.*?)[/quote]#si", "bbcode_QuoteNoAutor", $text);
  20. $text = preg_replace_callback("#[quote=(.*?)](.*?)[/quote]#si", "bbcode_QuoteAutor", $text);
  21. $text = preg_replace_callback("#[code](.*?)[/code]#si", "bbcode_Code", $text);
  22. $text = preg_replace_callback("#[php](.*?)[/php]#si", "bbcode_CodePhp", $text);
  23. return $text;
  24. }
  25. ?>


I jak mam
Cytat(aa)
blebleblelbelbe
Cytat(bb)
lebleblebleblebleb
blebleble


To jako quote mi bierze pierwsze
Cytat
i
:


Myślałem, żeby zakmnięcia quote szukać od tyłu, ale nie mam pomysłu jak to zrobić. Proszę o pomoc.
Go to the top of the page
+Quote Post
ActivePlayer
post 26.09.2005, 08:43:08
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 224
Pomógł: 40
Dołączył: 6.07.2004
Skąd: Wuppertal

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


  1. <?php
  2.  
  3. // Funkcja zamieniająca tagi [quote]tekst[/quote]
  4. function bbcode_QuoteNoAutor($string){
  5. $new_string ='<div class="quote">'.$string[1].'</div>';
  6. return $new_string;
  7. }
  8. // Funkcja zamieniająca tagi [quote=autor]tekst[/quote]
  9. function bbcode_QuoteAutor($string){
  10. $new_string = '<div class="header">'.$string[1].' napisał/a:</div>';
  11. $new_string.='<div class="quote">'.$string[2].'</div>';
  12. return $new_string;
  13. }
  14. function bbcode($text){
  15. $text = preg_replace_callback("#[img](.*?)[/img]#si", "bbcode_ImgNoAlt", $text);
  16. $text = preg_replace_callback("#[img=(.*?)](.*?)[/img]#si", "bbcode_ImgAlt", $text);
  17. $text = preg_replace_callback("#(.*?)#si", "bbcode_UrlNoName", $text);
  18. $text = preg_replace_callback("#(.*?)#si", "bbcode_UrlName", $text);
  19. while(strpos('[quote', $text)!==false){
  20. $text = preg_replace_callback("#[quote](.*?)[/quote]#si", "bbcode_QuoteNoAutor", $text);
  21. $text = preg_replace_callback("#[quote=(.*?)](.*?)[/quote]#si", "bbcode_QuoteAutor", $text);
  22. }
  23. $text = preg_replace_callback("#[code](.*?)[/code]#si", "bbcode_Code", $text);
  24. $text = preg_replace_callback("#[php](.*?)[/php]#si", "bbcode_CodePhp", $text);
  25. return $text;
  26. }
  27. ?>


sproboj tak, ew tego strposa na preg matcha mozesz podmienic gdyby problemy sprawial, a jak nie to zostaw bo jest szybszy.
Go to the top of the page
+Quote Post
quex
post 27.09.2005, 19:32:09
Post #3





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 11.02.2004

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


Ech, ale banalne to, zrobiłem tak:

  1. <?php
  2.  
  3. for($x=0;$x<=count(explode('[quote', $text));$x++){
  4. $text = preg_replace_callback("#[quote](.*?)[/quote]#si", "bbcode_QuoteNoAutor", $text);
  5. $text = preg_replace_callback("#[quote=(.*?)](.*?)[/quote]#si", "bbcode_QuoteAutor", $text);
  6. }
  7.  
  8. ?>
Go to the top of the page
+Quote Post

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: 19.07.2025 - 10:30