Lecture 4 - Regular expressions, form checking, and cookies - annotated

Lecture 4 - Regular expressions, form checking, and cookies - annotated

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Regular expressions, form checking, and cookies INFO/COM S 230: Intermediate Web Design and Programming In our last episode… Recall the following two functions: ereg($pattern, $string) – returns true if the $pattern appears in the $string ereg_replace($pattern, $sub, $string) – returns string in which all occurrences of $pattern in $string are replaced by $sub Example: L33T translator $input = $_POST["input"]; print("$input<br /> translates to<br />"); $result = strtoupper($input); $result = "OMG! ".$result; $trans = array( array("THE ", "TEH "), array("OWNS ", "PWNS "), array("CKS ", "XOR "), array("CKS!", "XOR!"), array("E", "3"), array("A", "4"), array("O", "0"), array("!", "!!!1!!!1!"), array("S ", "Z "), ); foreach ($trans as $t) { $result = ereg_replace($t[0], $t[1], $result); } print("$result <br /><br />"); Regular expressions Easy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 With ereg, ereg_replace, and split, can actually look for more complicated patterns via regular expressions. Regular expressions are patterns expressed via special symbols. * -- means zero or more of the preceding “character” + -- means one or more of the preceding “character” E.g. ereg(“a*”, “SpongeBob”) returns ereg(“ab*”, “SpongeBob”) returns ereg(“(ab)+”, “Krusty Krab”) returns ereg(“(ab)*”, “The Chum Bucket”) returns
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

Lecture 4 - Regular expressions, form checking, and cookies - annotated

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online