1) Write a regular expression for each of the following (1 point each)
- Matches "hello", "chello", and "jello"
- Matches "bal", "ball", and "balloon"
- Matches a string containing 5 word characters, followed by 1 underscore and 4 digits
- Matches any 5 digits followed by a dash, then another 4 digits
- Matches "pot", "bot", "boot", and "boooooooooooooooooot"
- Matches any 7 letter string without "z","q", or "x"
- Matches any 3 digit number without "0","1" or "5" followed by an underscore, 1 or more letters, another underscore and 5 letters
(example: 246_hello_world)
- Matches any html tag without an attribute
- Matches an honorific (Mr, Mrs, Ms, Dr) followed by a space, and Uppercase letter, then 0 or more letters followed by another space, then an Upper Case letter followed by 0 or more letters.
(example: Mr. Jeremy Anderson)
- Matches any 6 digit hex color code or 3 digit color code abbreviation value
2) Write a regular expression checker (5 points)
Create a web page (regEx.php) with a form with 2 fields which posts to itself.
- An element for you to enter text
- An element for you to enter a regular expression
When the form is submitted, it must call a function "checkRegEx()" which takes 2 arguments, the string and the regular expression. It must then use preg_match to check if the string entered matches the pattern in the regular expression. The function must show the string tested, the regex used, and the result (whether it is a match or not).
(Hint: You may need to use the stripslashes() function.)
3) Add-a-link page validation - 5 points
From the add-a-link in Homework 8, write an regular expression to validate the URL the user inputs. The regular expression must check for and allow the following:
- The URL must begin with "http://"
- The URL can optionally contain "www"
- If there is a www, the URL must have a "." followed by letters or numbers, followed by a valid top level domain (must use at least 5 valid TLDs).
Extra Credit
4) Add-a-link page formatting - 10 points
Modify your add-a-link display page to, in addition to displaying the title entered by the user, to go and check the URL entered for the title on that page. (i.e. the text between the <title> and </title> tags.) and display that as well.
Each link on your page should be displayed as follows:
User Title: Title entered by user here
Description: Description entered by user here
Link: URL entered by user
If there is no title on the page, Use the Title entered by the user for the title link instead and don't display the "User Title" information line.
You may add other information as needed, but it is not required (i.e. The user who submitted the link, the date, etc)
5)Grab meta tags
For number 4 above, modify the code to grab the information from the meta tag for description (if the page has it), and change the display to include the that text instead of the user submitted text with a link called "user comments" below which links to a page showing the comments entered by the user for that page.
Hints:
- To open the web page, you may want to look at fopen() or fsockopen().
- For debugging, you can use print_r($matches) to see all the information in the $matches array.
- You may need to escape some characters in your regular expression
- You may want to remove all the new lines, tabs, and returns in the web page with a regular expression
NEXT
PREVIOUS
Master Index