[ Zoran Rašković @ 14.08.2002. 06:09 ] @
Ne mogu da se pohvalim da sam u potpunosti ovladao regularnim izrazima, ali mi je ovo stvarno hitno... Naime, imam:

Code:

$msg1 = preg_replace("/\[code\](.*)\[\/code\]/i", "<table border=0 align=center width=90% cellpadding=3 cellspacing=1><tr><td class='code'><b>Code:</b><br><font color='green'>\\1</font><br></td></tr></table>", $msg1);


Problem je sto ovaj code lepo radi ako bih sve napisao i jednom redu, ali ako pritisnem enter vise puta i zavrsim code tag, onda ga uopste ne renderuje lepo vec samo prikaze ovaj gornji code na stranici.

Isti mi je slucaj i kod quote tagova:

Code:

$msg1 = preg_replace("/\[quote\](.*)\[\/quote\]/i", "<blockquote><font size=1>quote:</font><hr>\\1<hr></blockquote>", $msg1);


Znaci ako napisem u jednom redu onda je ok, ali ako pritiskam enter onda ne renderuje uopste :(

Hvala na pomoci,
Zoran
[ Gojko Vujovic @ 14.08.2002. 13:06 ] @
Dodaj 'm' pattern modifier, dakle:
$msg1 = preg_replace("/\[code\](.*)\[\/code\]/im"...

[ Dejan Topalovic @ 14.08.2002. 14:18 ] @
Da dodam samo...
m identifier oznacava multiline.

http://www.php.net/manual/en/pcre.pattern.modifiers.php

m (PCRE_MULTILINE)
By default, PCRE treats the subject string as consisting of a single "line" of characters (even if it actually contains several newlines). The "start of line" metacharacter (^) matches only at the start of the string, while the "end of line" metacharacter ($) matches only at the end of the string, or before a terminating newline (unless D modifier is set). This is the same as Perl.

When this modifier is set, the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively, as well as at the very start and end. This is equivalent to Perl's /m modifier. If there are no "\n" characters in a subject string, or no occurrences of ^ or $ in a pattern, setting this modifier has no effect.

[ Zoran Rašković @ 14.08.2002. 19:02 ] @
Dodao sam ovaj m modifier ali je ista prica i dalje :(, znaci ne prikazuje kako treba:

Code:

$name=stripslashes($myrow[1]);
$name=htmlspecialchars($name);
$msg1=$myrow[2];
$msg1=htmlspecialchars($msg1);
$msg1=stripslashes($msg1);
$msg1=nl2br($msg1);

$msg1 = preg_replace("/\[quote\](.*)\[\/quote\]/im", "<blockquote><font size=1>quote:</font><hr>\\1<hr></blockquote>", $msg1);

$msg1 = preg_replace("/\[code\](.*)\[\/code\]/im", "<table border=0 align=center width=90% cellpadding=3 cellspacing=1><tr><td class='code'><b>Code:</b><br><font color='green'>\\1</font><br></td></tr></table>", $msg1);

echo "<B>$name</B><p>$msg1";
[ -zombie- @ 15.08.2002. 03:29 ] @
probaj 's' patern modifier umesto 'm'... to meni uvek zavrsi posao...

a cisto da se ne bi vratio opet ovde, dodaj i 'U' modifier, koji oznacava "ungreedy", sto u prevodu znaci da ako imash na dva mesta po par [code] tagova, sa 'U' modifierom nece da uhvati pocetak prvog i kraj zadnjeg, nego ce da ih odradi odredjeno...

znaci, moja licna preporuka je 'isU' pattern modifier string... ovo ja uglavnom koristim...

a josh vise preporucujem da malo i RTFM o pattern modifierima...

http://www.php.net/manual/en/pcre.pattern.modifiers.php

Citat:

s (PCRE_DOTALL)
If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier.
[ Zoran Rašković @ 15.08.2002. 04:21 ] @
To je to, hvala jos jednom.
[ bugsu @ 17.06.2009. 10:55 ] @
dizem temu iz mrtvih al zato sto imam problem ...

uradim ovo
Code:
$description = "[vid]596[/vid] taj broj";
$search = "/\[vid\](.*)\[\/vid\]/isU";
$replace = "Broj je \\1";

$msg = preg_replace($search, $replace, $description);
echo $msg;


i ja za echo dobijem
Broj je 596 taj broj



a meni treba samo da zameni tj da ispise ...Broj je 596
i to je sve....u cemu gresim?
[ Nikola Poša @ 17.06.2009. 11:17 ] @
Pogrešno si shvatio ideju preg_replace-a... On ne treba da zameni ceo taj $description za tvoj $replace, već on menja taj pattern sa onim što mu ti pošalješ kao replacement:
Citat:
Searches subject for matches to pattern and replaces them with replacement.

Ono što ti hoćeš možeš da postigneš ovako:
Code:

$description = '[vid]596[/vid] taj broj';
$search = '/\[vid\](.+)\[\/vid\]/Uis';

preg_match($search, $description, $niz);

echo 'Broj je ' . $niz[1];
[ bugsu @ 17.06.2009. 11:23 ] @
jaooo ...puko sam definitivno ....dobro sam ja svatio ...to meni i treba...samo nzm sta mi bi da pitam...pad koncentracije izgleda :/


jer pravim embed kod ....i [vid] - [/vid] treba da zameni sa emebed kodom a ostalo ostavi :s.....izvini na cimanju ...