I have searched for the explanation/meaning of following website validation code in PHP,but didnt get it. Any clue?
(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website))
I have searched for the explanation/meaning of following website validation code in PHP,but didnt get it. Any clue?
(!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website))
If you google preg_match you will find a reference to a php method which performs a regular expression match.
Your code checks if $website matches the pattern between " ", if it doesn't matches it returns true. It is a condition which checks for a match to the regular expression given in pattern.
The preg_match can be called as:
preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
In your case the $pattern
is "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i"
and the $subject
/ the input string is $website
. Which seems to be checking for https and ftp.
You can enter your pattern string in a website like this one and hover over each element for a clue as to what it means.