note 22014 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:06:33 +0000
Subject: note 22014 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55706@lists.php.net to get a copy of this message
Note Submitter: lonestarn8@netscape.com ---- Just a note regarding the "limit" flag... I was trying to parse an XML file looking for an entire Element, with an Attribute that matched a certain ID. Well, when the Element to be matched was in the middle of my XML file, the preg_replace would come back false. But when the Element to be matched was at the beginning of the file, the preg would match greedily, and slurp in the whole file. So what I had to do was specify a LIMIT in my preg_replace. Since I knew that there should only be one element with any given Attribute, I set the limit to "1", and it works great. So if you're having problems with matches in the middle of your search string, try setting a "limit" on the number of matches. Syntax eg: $slurper = preg_replace($pattern, $replace, $subject, 1); Hope this helps.

« previous php.notes (#55706) next »