I have this ( preg_match('/^\d*$/', $nr_procedimento) ? 'f' : 't';
) in a code, but I have no idea what it does, more precisely the preg_match('/^\d*$/'
part. Anyone know?
I have this ( preg_match('/^\d*$/', $nr_procedimento) ? 'f' : 't';
) in a code, but I have no idea what it does, more precisely the preg_match('/^\d*$/'
part. Anyone know?
The function preg_match
makes a match of a regular expression in a string, returning 1
if match, 0
if it did not match% and false
if an error has occurred.
You pass two parameters to it, the first being a regular expression and the second the string to veriricada.
In your case the regex is /^\d*$/
, defining each part:
/ indicates the beginning of the regular expression
^ indicates that your pattern starts as follows
\ d defines numeric values
* sets the previous element can occur 0 or No times
$ indicates that your string should end here
/ indicates the end of the regular expression
You can see more about preg_match
href="http://php.net/manual/pt_BR/function.preg-match.php"> here.
In your example you have a complete ternary .
preg_match('/^\d*$/', $nr_procedimento) ? 'f' : 't';
In this case, if the content of the $nr_procedimento
der match the regex shown, the f
will be returned by the ternary otherwise% is returned t
.
It's a regular expression to fetch a line that starts and ends with numbers. The heaped symbols are known as meta characters , each one has a function:
^
- means start line.
\d
- is an abbreviation for [0-9] or just numbers.
*
- makes the combination greedy, if as many times as possible the defined pattern.
$
- means end of line