note 99657 added to function.preg-match

From: Date: Sun, 29 Aug 2010 17:49:05 +0000
Subject: note 99657 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-172146@lists.php.net to get a copy of this message
Though the documentation states that the return value on error will be FALSE (aka bool(false)), preg_match() in fact returns int(0). Always check preg_last_error(), which gives the truth.. <?php // Ensure we hit the recursion limit ini_set('pcre.recursion_limit', 1); // See http://us.php.net/preg_last_error $ret = preg_match('/(?:\D+|<\d+>)*[!?]/', 'foobar foobar foobar'); echo 'Return value is '; var_dump($ret); if ($ret === false) { echo '$ret is false; preg_last_error() says: ' . preg_last_error() . "\n"; } else { echo '$ret is not false; preg_last_error() says: ' . preg_last_error() . "\n"; } ---- Server IP: 208.69.120.55 Probable Submitter: 69.181.203.142 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/99657 Del: integrated -- https://master.php.net/note/delete/99657/integrated Del: useless -- https://master.php.net/note/delete/99657/useless Del: bad code -- https://master.php.net/note/delete/99657/bad+code Del: spam -- https://master.php.net/note/delete/99657/spam Del: non-english -- https://master.php.net/note/delete/99657/non-english Del: in docs -- https://master.php.net/note/delete/99657/in+docs Del: other reasons-- https://master.php.net/note/delete/99657 Reject -- https://master.php.net/note/reject/99657 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172146) next »