Page 2 of 2

Posted: Wed Feb 22, 2006 3:35 pm
by feyd
now you've got a more fun infinite loop.

Code: Select all

[/quote][quote]

Posted: Wed Feb 22, 2006 3:39 pm
by evilmonkey
Damn, damn, damn!

Code: Select all

while (preg_match("'@\[quote=(.*?)\](.*?)\[/quote\]@ims'",$text)!=0){
?

EDIT: That doesn't even work...:(

Posted: Wed Feb 22, 2006 3:51 pm
by feyd
you've got some boo boo's in your regex. ;)

Code: Select all

<?php

ob_start();

?>
[quote=test1]test1[/quote]
[quote=test2
]test2[/quote]
[quote=test3]
test3
[/quote]test4
[/quote]test4[quote=]
test5[/quote]
<?php

$t = ob_get_clean();

preg_match_all("'@\[quote=(.*?)\](.*?)\[/quote\]@ims'",$t,$m);	//	<-- yours

var_export($m);

preg_match_all('@\[quote=(.*?)\](.*?)\[/quote\]@ims',$t,$m);

var_export($m);

?>

Code: Select all

array (
  0 =>
  array (
  ),
  1 =>
  array (
  ),
  2 =>
  array (
  ),
)

array (
  0 =>
  array (
    0 => '[quote=test1]test1[/quote]',
    1 => '[quote=test2
]test2[/quote]',
    2 => '[quote=test3]
test3
[/quote]',
    3 => '[quote=]
test5[/quote]',
  ),
  1 =>
  array (
    0 => 'test1',
    1 => 'test2
',
    2 => 'test3',
    3 => '',
  ),
  2 =>
  array (
    0 => 'test1',
    1 => 'test2',
    2 => '
test3
',
    3 => '
test5',
  ),
)
although using modifier m and s seems a bit odd. s should suffice.

Posted: Wed Feb 22, 2006 4:34 pm
by evilmonkey
Yup, that did it. Thanks feyd!

Posted: Wed Feb 22, 2006 11:06 pm
by josh
evilmonkey wrote:
jshpro2 wrote:Yeah your while loop should be checking for the same text it is going to replace (regex), also this is a good place for a do..while loop

while loop for simple quote
check string
replace text
check string

do..while loop for simple quote
replace text
check string
I don't think do while is good for this case...why run the memory intensive regex function if there's no
tag at all?
You run a regex no matter what on your loop..

With the do while it runs a replacement so for a post with only one single
foo
only two regexes get run, the replacement and the check, whereas in a while loop it checks to see if there is a quote, then replaces it, then checks again to make sure it got them all, a total of 3 checks. The do..while is more efficient.