Skip to content

Instantly share code, notes, and snippets.

@daylik
Created March 9, 2017 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daylik/15c35e67cf09b7f556a49971d3121e50 to your computer and use it in GitHub Desktop.
Save daylik/15c35e67cf09b7f556a49971d3121e50 to your computer and use it in GitHub Desktop.
<?php
$currentCatId = '1,2';
function is_var_ok( $var, $reg ){
if(isset($reg)){
$is_filter_ok = $reg;
} else {
$is_filter_ok = '#^[0-9,\s]+$#'; //проверка на вхождения в струку только 0-9 запятой и пробелов
}
if( isset($var) && preg_match($is_filter_ok, $var) && $var != 0 && $var != '' ){
return true;
} else {
return false;
}
}
//do it
if( is_var_ok($currentCatId, '#^[0-9,\s]+$#') ){
echo $currentCatId;
} else {
echo 'false';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment