Preg_match using an array?

Proper use: /,,([,]+)?|^,|,$|\b,\b|\s,/

$comma[0] = '/,,([,]+)?/';  
            $comma[1] = '/^,/';     
            $comma[2] = '/,$/';
            $comma[3] = '/\b,\b/';  
            $comma[4] = '/\s,/';    

$analyst = preg_match($comma, $_POST['analyst']) 
    ? mysql_real_escape_string($_POST['analyst']) : NULL;

I am trying to detect commas from user input, each regular expression is defined correctly, but I do not understand why it does not pass them to the if statement.

Edit:

if i change this:

$analyst = preg_match('test', $_POST['analyst']) 
    ? mysql_real_escape_string($_POST['analyst']) : NULL;

then it works, it does not make sense.

+3
source share
2 answers

preg_match () does not accept arrays as arguments, only strings.

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )

http://php.net/manual/en/function.preg-match.php

+4
source

preg_match accept the first parameter as a string, and you pass an array.

+1
source

All Articles