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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

egexes, they will become a powerful tool for pattern matching.<br />

<br />

<br />

TEST_DATA;<br />

/*<br />

* Use str_replace() to highlight any occurrence of the word<br />

* "regular"<br />

*/<br />

echo str_replace("regular", "regular", $string);<br />

/*<br />

* Use preg_replace() to highlight any occurrence of the word<br />

* "regular"<br />

*/<br />

echo preg_replace("/regular/", "regular", $string);<br />

?><br />

<br />

<br />

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

Executing this script in your browser outputs the test information twice, with identical results (see<br />

Figure 9-2).<br />

Figure 9-2. The word regular highlighted with both regexes <strong>and</strong> regular string replacement<br />

315

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

Saved successfully!

Ooh no, something went wrong!