Preg_match using array?
Correct usage is: /,,([,]+)?|^,|,$|\b,\b|\s,/
$comma[0] = '/,,([,]+)?/';
开发者_JAVA百科 $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 the users input, each regex is defined properly, but I do not understand why it isn't passing them into the if statement.
Edit:
if I change this:
$analyst = preg_match('test', $_POST['analyst'])
? mysql_real_escape_string($_POST['analyst']) : NULL;
then it works, this makes no sense.
preg_match() doesn't 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
preg_match accept first parameter as string and you are passing an array.
精彩评论