code_newbie code_newbie -4 years ago 126
PHP Question

PHP - preg_match explanation

Im a beginner in PHP I just want to ask can someone explain to me this line of code.

(preg_match('/^\w{5,}$/', $username))


Thankyou in advance. :) Your answer is so much appreciated. :)

Answer Source

According to the comments your problem is about understanding regular expressions not PHP.

/^ Beginning of line, correct

$/ End of line, correct

\w Any word character (letter, number, underscore)

a{3,} 3 or more of a

Therefore: If there are 5 or more any word characters in the username the function returns a positive result.

Or even easier: A username needs to contain at least five any word characters.

Learn more about regular expressions and how they work. Some explanation in this comment: http://php.net/manual/de/function.preg-match.php#105924

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download