Code: Select all
[/quote][quote]Moderator: General Moderators
Code: Select all
[/quote][quote]Code: Select all
while (preg_match("'@\[quote=(.*?)\](.*?)\[/quote\]@ims'",$text)!=0){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',
),
)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.evilmonkey wrote:I don't think do while is good for this case...why run the memory intensive regex function if there's nojshpro2 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 stringYou run a regex no matter what on your loop..tag at all?
With the do while it runs a replacement so for a post with only one singlefoo