php - Preg Match a string with $, numbers, and letters -
i'm trying preg_match string.
$word = "$1$s"; or $word = "$2$s" if(preg_match('/^\$[1-9]{1}\$s$/' ,$word)){ echo 'true'; } else { echo 'false'; } i tried not giving true result. how can make true.
php trying render variable $s in double quoted string. use single quotes instead , can remove {1} inside regular expression because not necessary.
$word = '$1$s'; if (preg_match('/^\$[1-9]\$s$/', $word)) { echo 'true'; } else { echo 'false'; } you can escape $ in double quoted string:
$word = "$1\$s"; // note $1 doesn't need escaped since variables can't start numbers finally, can see why wasn't working seeing $word equaled (with error reporting enabled):
$word = "$1$s"; // notice: undefined variable: s on line # echo $word; // $1
Comments
Post a Comment