note 81424 added to function.ereg

From: Date: Wed, 27 Feb 2008 19:23:11 +0000
Subject: note 81424 added to function.ereg
Groups: php.notes 
Request: Send a blank email to php-notes+get-136534@lists.php.net to get a copy of this message
It's important to note for certain regular expression that your $regs[] array will only contain as many values as you have sets of parenthesis in your regexp. (plus 1, of course) For example, the regexp below was designed to locate tags enclosed in <> characters inside a string: <?php ereg("^([^<]*)(<[^>]+>[^<]*)*$", $str, $tags) ?> This will *not* create an arbitrarily long array in $tags for the number of tags that it finds. Given the string "This <has> a <couple> of <tags> in it", you'll see: 0 : This <has> a <couple> of <tags> in it 1 : This 2 : <tags> in it Since the same parenthesized section of the regexp is matching all tags found, it overwrites the same section of the array. If you try increasing the number of parenthesis, it just creates duplicates of the same result. ---- Server IP: 209.41.74.194 Probable Submitter: 71.72.89.165 ---- Manual Page -- http://www.php.net/manual/en/function.ereg.php Edit -- https://master.php.net/note/edit/81424 Del: integrated -- https://master.php.net/note/delete/81424/integrated Del: useless -- https://master.php.net/note/delete/81424/useless Del: bad code -- https://master.php.net/note/delete/81424/bad+code Del: spam -- https://master.php.net/note/delete/81424/spam Del: non-english -- https://master.php.net/note/delete/81424/non-english Del: in docs -- https://master.php.net/note/delete/81424/in+docs Del: other reasons-- https://master.php.net/note/delete/81424 Reject -- https://master.php.net/note/reject/81424 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#136534) next »