Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> preg replace callback + zagniezdzony bbcode
deniol13
post
Post #1





Grupa: Zarejestrowani
Postów: 190
Pomógł: 2
Dołączył: 30.11.2009

Ostrzeżenie: (10%)
X----


witam, jak zastosowac preg replace callback aby dzialal zagniezdzony bbcode? mam np taki regexp i czesc kodu

  1. $regExp = '\[code\](.*)\[\/code\]';
  2. $text = preg_replace_callback( '/' . $regExp . '/siU', array( $this, 'codeParse' ), $text, 9999 );


a metoda codeParse wyglada tak

  1. private function codeParse( $text )
  2. {
  3. if( is_array( $text ) )
  4. {
  5. $text = '<div class="code">' . $text[1] . '</div>';
  6. }
  7.  
  8. return $text;
  9. }


jak jest pojedynczy code lub sa dwa ale oddzielne to jest ok, ale jak juz jeden dam w drugi to nie za bardzo (zagniezdzone)

podbijam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
deniol13
post
Post #2





Grupa: Zarejestrowani
Postów: 190
Pomógł: 2
Dołączył: 30.11.2009

Ostrzeżenie: (10%)
X----


dzieki ale nie powiem czy dziala, sam rozwiazelem problem (IMG:style_emoticons/default/biggrin.gif) (huraaaa, pol litrwa kawy z mlekiem + nerwy robi swoje)

jak by ktos mial podobny problem,
  1. private function codeParse( $matches )
  2. {
  3. if( is_array( $matches ) )
  4. {
  5. $replacments = 0;
  6.  
  7. $matches = $matches[0];
  8.  
  9. while( true )
  10. {
  11. $matches = preg_replace( '#\[code\](.*)\[/code\]#siU', '<div class="code_body"><div class="code_head">Kod</div><div class="code_text">$1</div></div>', $matches, 999, $replacments );
  12.  
  13. if( $replacments == 0 )
  14. {
  15. break;
  16. }
  17. }
  18.  
  19. return $matches;
  20. }
  21. else
  22. {
  23. return $matches[1];
  24. }
  25. }
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 6.10.2025 - 23:40