1

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. :)

Blackbam
  • 17,496
  • 26
  • 97
  • 150
  • How about reading the documentation? http://php.net/manual/de/function.preg-match.php – Blackbam Feb 28 '17 at 16:22
  • actually. I've tried reading many topics about preg_match but still its hard for me to understand. the ('/^) in the code says that it was a start of the pattern and ($/') is the ending of it. now i struggle in \w{5,} I cant understand this. can you help me? :( – code_newbie Feb 28 '17 at 16:26
  • http://www.regular-expressions.info/characters.html#special http://www.regular-expressions.info/repeat.html – AbraCadaver Feb 28 '17 at 16:38

1 Answers1

1

Your PHP match string is

/^\w{5,}$/

and a PHP match string is surrounded by / characters which are not part of the RegEx string itself.
According to the comments your problem is about understanding regular expressions, not PHP.

^ is the beginning of the line, correct

$ is the end of the line, correct

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

a{5,} does mean 5 or more characters '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 can be found in this comment.

zx485
  • 28,498
  • 28
  • 50
  • 59
Blackbam
  • 17,496
  • 26
  • 97
  • 150
  • wow! now i understand thanks man. :) This gives hope. XD thankyousomuch. :) – code_newbie Feb 28 '17 at 16:38
  • 1
    stricly speaking `^` matches the start of a line and `$` matches the end of a line – Brad Feb 28 '17 at 22:06
  • yes you are right – Blackbam Feb 28 '17 at 23:26
  • Thank you for the help guys. Much appreciated. :) Now I understand how to use it. :) btw i cant post any more question. i would like to ask what is wrong in this code it keeps printing that the account do not exist eventhough it is. Im using xampp version 7 and i think that @mysql_result is the problem can you help me please. :3 – code_newbie Mar 01 '17 at 02:49
  • Im cringing right now because this is my project for web based subject in our school. and tomorrow is my defense im still stuck at this. :( – code_newbie Mar 01 '17 at 02:50