Re: PHP 4.0 Bug #7222 Updated: ereg_replace, ereg

From: Date: Mon, 16 Oct 2000 21:11:09 +0000
Subject: Re: PHP 4.0 Bug #7222 Updated: ereg_replace, ereg
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-35194@lists.php.net to get a copy of this message
joey@php.net writes: > ID: 7222 > Updated by: joey > Reported By: zibin@tx.technion.ac.il > Status: Closed > Bug Type: *Regular Expressions > Assigned To: > Comments: > > Actually, the problem is in the escaping of the [ and ]. > > The first \ is being eaten by the PHP parser. > > What you really want is > > eregi("onlyuser\\\[(.*?)\\\]",$inside, $regs) S'pose I could be wrong--but that code doesn't do anything useful. Given the string: $inside = 'This is onlyuser[one]<br>\n'; the snippet you give returns false. It works, however, with the string $inside = 'This is onlyuser\\\[one\\\]<br>\n'; ...except that it's matched the string 'onlyuser\\', which I don't think is what the poster was after, and doesn't match anything in the parens. <pre> <?php error_reporting(E_ALL); $inside = 'This is onlyuser[one]<br>\n'; if (eregi("onlyuser\[(.*)\]", $inside, $regs)) { echo "Found: "; print_r($regs); } else { echo "<br>\nNot found.<br>\n"; } echo "<hr>"; if (eregi("onlyuser\\\[(.*?)\\\]", $inside, $regs)) { echo "Found: "; print_r($regs); } else { echo "<br>\nNot found.<br>\n"; } ?> </pre> For the above, I get: Found: Array ( [0] => onlyuser[one] [1] => one [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => ) --------------------------- Not found. I suggested going to preg_match_all() since it looked like the poster was looking for more than one instance of onlyuser[foo] in the text, which would be a PITA to do with ereg*(). -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.dev (#35194) next »