need help with pattern matching in arrays

I am hosting a forum running PHPBB software (written in PHP).
I added a 3rd party modifiction to my forum, that allows the user to add a link to their facebook page in their profile.
There is one line of code that checks the pattern of what the user enters in this text field,
and displays an error if what the user enters doesn’t meet the required pattern or format.

[php]
‘facebook’ => array(array(‘string’, true, 12, 255),array(‘match’, true, ‘#^http[s]?://(.?.)?[a-z0-9-]+.[a-z]{2,4}#i’)),
[/php]

  I'm been frustrated trying to understand this line of code and the specific pattern it's testing for. I can't find any PHP reference page to help me
     intrerpret the pattern it's testing for and also help me change it to my preferred pattern.

   I'd like to modify the above line of code to reject any entry that doesn't begin  with http://www.facebook.com/

  I would greatly appreciate some help with this.

Let me break it down for you into bite size chunks…

#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i

The # at beginning/end are markers telling php where to begin matching, they are usually / (forward slashes) but as you’re checking
a URL, using # makes it easier to read for a human.

^ This symbol says 'hey, this is the beginning of the pattern we want to match.
The next thing it does is check if http (or https) is present. (the ? straight after tells the interpreter that the ‘s’ may not be present.) followed by ://

The next bit in the parenthesis:
The .* means any char . any amount of times * maybe present ? there may even be a fullstop .
(notice the fullstop is escaped . do not confuse with any char . symbol)

and again we have any amount of times * maybe present ?

Keeping up? Great…
Next bit is grouped together using square brackets [ ]
This says we will accept a-z 0-9 - ONLY! (again notice the hyphen is escaped -)
The + sign says it must be present at least once but maybe more.
Followed by a fullstop .
Then finally we are looking for the chars a-z and between 2 and 4 chars in length.

The last i on the very end says case insensitive (boo, BOO, Boo etc.)

Hope that helps,
Red. :wink:

Very helpful! Thanks

Sponsor our Newsletter | Privacy Policy | Terms of Service