note 123724 deleted from function.mb-ereg-match by cmb
| From: | cmb@php.net | Date: | Mon, 08 Nov 2021 18:54:35 +0000 |
| Subject: | note 123724 deleted from function.mb-ereg-match by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217162@lists.php.net to get a copy of this message | ||
Note Submitter: webdesign at innato dot nl
----
It took me a while to discover that you must escape characters like parentheses (), square brackets
[] and ^ (and maybe more) if you want to match these as a literal. Otherwise you may get some
erratic outcome.
In summary, using a match anywhere in the string as an example:
<?php
$needle = "[";
$haystack = "some_array[]";
$test= mb_ereg_match(".*".$needle, $haystack); // returns false and a php warning
$test= mb_ereg_match('.*'.preg_quote($needle), $haystack); // returns true
?>