note 124981 added to function.preg-match

From: Date: Wed, 06 May 2020 08:39:15 +0000
Subject: note 124981 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-214584@lists.php.net to get a copy of this message
As of PHP 7.2, you can use the following. If you work with named subpatterns and dont want to bother with unnamed match result entries and unmatched subpatterns, just replace preg_match() with named_preg_match(). This filters all unwanted stuff out. <?php function named_preg_match(string $pattern , string $subject, array &$matches = null, int $flags = 0, int $offset = 0) { $retval = preg_match($pattern, $subject, $localmatches, PREG_UNMATCHED_AS_NULL | $flags, $offset); if ($retval) { foreach ($localmatches as $key => $value) { if (is_int($key)) $value = null; if (is_null($value)) unset($localmatches[$key]); } $matches = $localmatches; } return $retval; } ?> Hope this will be useful. ---- Server IP: 45.112.84.4 Probable Submitter: 185.85.3.195 (proxied: 80.242.181.162) ---- Manual Page -- http://php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/124981 Del: integrated -- https://master.php.net/note/delete/124981/integrated Del: useless -- https://master.php.net/note/delete/124981/useless Del: bad code -- https://master.php.net/note/delete/124981/bad+code Del: spam -- https://master.php.net/note/delete/124981/spam Del: non-english -- https://master.php.net/note/delete/124981/non-english Del: in docs -- https://master.php.net/note/delete/124981/in+docs Del: other reasons-- https://master.php.net/note/delete/124981 Reject -- https://master.php.net/note/reject/124981 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#214584) next »