Re: help! strange preg_match no match problem!
- From: "Peter H. Coffin" <hellsop@xxxxxxxxxxxxx>
- Date: Fri, 27 Jun 2008 11:56:04 -0500
On Fri, 27 Jun 2008 09:23:46 -0700 (PDT), Happy Face wrote:
Hi, All,
I encountered this strange problem while using function preg_match.
The following is the php code.
when I set the line:
$text = str_repeat('*', 12500);
preg_match will return 0 for the hard coded regular expression.
but if I set $text to 12499, it will return 1 for a match.
$text = str_repeat('*', 12499);
anybody know what's the problem?
Thanks!
</p>match result
<?php
$text = str_repeat('*', 12500);
$regexp = "/ ( . *? ) ( ($)|(~(?: [[:alnum:]]+ | .))|(\#? \[ .*? [^]
\s] .*? \]) ) /Asx";
if($text and $regexp)
$ret = preg_match($regexp, $text, $m);
echo $ret;
?> <br />
</p>regexp is <?php echo $regexp; ?> <br />
</p>text length <?php echo strlen($text) ?> <br>
<?php echo "count ".count($m)."<br>";
for ($i=0; $i<count($m); $i++) {
$str=$i.htmlentities($m[$i])."<br>";
echo $str;
} ?> <br />
Can't replicate. I get hits regardless of length:
$ cat foo.php
<?php
$text = str_repeat('*', 12499);
$regexp = "/ ( . *? ) ( ($)|(~(?: [[:alnum:]]+ | .))|(\#? \[ .*? [^]\s] .*? \]) ) /Asx";
if($text and $regexp)
$ret = preg_match($regexp, $text, $m);
echo "$ret\n";
?>
$ php foo.php
1
$ cat foo1.php
<?php
$text = str_repeat('*', 12500);
$regexp = "/ ( . *? ) ( ($)|(~(?: [[:alnum:]]+ | .))|(\#? \[ .*? [^]\s] .*? \]) ) /Asx";
if($text and $regexp)
$ret = preg_match($regexp, $text, $m);
echo "$ret\n";
?>
$ php foo1.php
1
$
--
9. If a self-destruct mechanism is necessary, it will not be a large red button
labelled "Danger: Do Not Push". The big red button marked "Do Not Push" will
instead trigger a spray of bullets on anyone stupid enough to disregard it.
--Peter Anspach's list of things to do as an Evil Overlord
.
- Follow-Ups:
- Re: help! strange preg_match no match problem!
- From: Happy Face
- Re: help! strange preg_match no match problem!
- References:
- help! strange preg_match no match problem!
- From: Happy Face
- help! strange preg_match no match problem!
- Prev by Date: Re: Please Help Troubleshoot My First Real Function
- Next by Date: Re: Please Help Troubleshoot My First Real Function
- Previous by thread: help! strange preg_match no match problem!
- Next by thread: Re: help! strange preg_match no match problem!
- Index(es):
Relevant Pages
|