What does this php function mean? Preg_replace (& #039; ^. +? U & #039;, & #039; & #039;, $ auth) What does this php function mean?
Preg_replace ('/^. +? /U', '', $ auth)
Reply content:
What does this php function mean?
Preg_replace ('/^. +? /U', '', $ auth)
FunctionPreg_replace
You should know how to use regular expressions to replace strings. If you do not understand the regular expression, read the official documentation.
Let me explain this regular expression.'/^. +? /U'
.
ModifierU
Indicates reversing the greedy mode 」.
Regular Expressions are greedy by default, that is+
*
If multiple characters can be matched, try to match more characters unless+?
*?
.
HoweverU
After modifier, the greedy mode is not used by default,+
*
Non-Greedy match,+?
*?
Instead, try to match more characters.
For more details, see the official documentation or searchRegular Expression PCRE_UNGREEDY
.
So,/^. +? /U
Actually equivalent/^. +/
, Indicates all characters starting from the beginning.
Therefore, this function means to replace all the characters starting from the beginning with an empty string. (Although I don't know what it means to write such a round expression in addition to the interview test)