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

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

Info icon This 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.
Image of page 1

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

View Full Document Right 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 ^ -- matches when the following
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern