Pogledajte određenu poruku
Staro 28. 02. 2008.   #1
Bojsi
član
Certified
 
Datum učlanjenja: 24.01.2007
Poruke: 92
Hvala: 1
802 "Hvala" u 15 poruka
Bojsi is on a distinguished roadBojsi is on a distinguished roadBojsi is on a distinguished roadBojsi is on a distinguished roadBojsi is on a distinguished roadBojsi is on a distinguished roadBojsi is on a distinguished road
Smile Formatiranje teksta uz pomoc custom tagova

Pozdrav,

Pravim php skritpu koja parsira custom "[ tag ]" tagove (slicne kao na ovom forumu) uz pomoc sledece tehnike:

PHP kôd:
$Patterns[] = "|\[code\](.*?)\[/code\]|s";
$Patterns[] = "|\[url\](.*?)\[/url\]|s";
$Patterns[] = "|\[url=(.*?)\](.*?)\[/url\]|s";
            
$Replaces[] = "<div class=\"code\">\$1</div>";
$Replaces[] = "<a href=\"$1\" target=\"_blank\" title=\"$1\">\$1</a>";
$Replaces[] = "<a href=\"$1\" target=\"_blank\" title=\"$1\">\$2</a>";

echo 
nl2br(preg_replace($Patterns$Replaces$Text)); 
Kao sto mozete videti u kodu, uz pomoc nl2br funkcije najpre pretvaram svaki novi red u </ br> tag, a zatim parsiram ostatak teksta uz pomoc preg_replace funkcije.

Problem mi nazalost nastaje kod [ code ] tagova gde bih zeleo da izbegnem efekat nl2br funkcije, vec da tekst ostane pre-formatiran (kao kod upotrebe pre taga).

Da li je nekako moguce to odraditi, tj. iskljuciti nl2br unutar nekih tagova? Nisam siguran da li se nekako nl2br funkcija moze zaobici i sve uraditi uz pomoc regularnih izraza, ali mozda nekom to da ideju

Hvala unapred na svakoj pomoci.
Bojsi je offline   Odgovorite uz citat