Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [bbcode] problem z [quote]
Forum PHP.pl > Forum > PHP
quex
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.
ActivePlayer
  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.
quex
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. ?>
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.