PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Preg match

Returns 1 if the pattern matches given subject. Returns 0 if it does not. Returns FALSE if an error occurred.
 
$str = '
    PHP allowed variable names: $a, $_b, $a10, $A, $_ 
    PHP not allowed: $1, $-'
;

$flag = preg_match('/[$][a-zA-Z_][A-Za-z_0-9]*/', $str);

var_dump($flag); // int 1
... 1 lines
 
If matches is provided, then matches is filled with the results array.
 
preg_match('/[$][a-zA-Z_][A-Za-z_0-9]*/', $str, $matches);

var_dump($matches[0]); // $a
Preg match all
 
preg_match_all('/[$][a-zA-Z_][A-Za-z_0-9]*/', $str, $matches);

var_dump($matches[0]); // $a, $_b, $a10, $A, $_

Questions    
Search in array

        A B C D E F
🔔
1/2