02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

316<br />

CHAPTER 9 ■ PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS<br />

Drilling Down on the Basics of Pattern Modifiers<br />

You may have noticed that the word regular in the title is not highlighted. This is because the previous<br />

example is case sensitive.<br />

To solve this problem with simple string replacement, you can opt to use the str_ireplace()<br />

function, which is nearly identical to str_replace(), except that it is case insensitive.<br />

With regular expressions, you will still use preg_replace(), but you’ll need a modifier to signify case<br />

insensitivity. A modifier is a letter that follows the pattern delimiter, providing additional information to<br />

the regex about how it should h<strong>and</strong>le patterns. For case insensitivity, the modifier i should be applied.<br />

Modify regex.php to use case-insensitive replacement functions <strong>by</strong> making the modifications shown<br />

in bold:<br />

<br />

<br />

<br />

<br />

Regular Expression Demo<br />

<br />

em {<br />

background-color: #FF0;<br />

border-top: 1px solid #000;<br />

border-bottom: 1px solid #000;<br />

}<br />

<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!