05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

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.

A simple use of positive lookahead is splitting a Unix mbox mail file into individual<br />

messages. The word "From" starting a line by itself indicates the start of a new message,<br />

so you can split the mailbox into messages by specifying the separator as the<br />

point where the next text is "From" at the start of a line:<br />

$messages = preg_split('/(?=^From )/m', $mailbox);<br />

A simple use of negative lookbehind is to extract quoted strings that contain quoted<br />

delimiters. For instance, here’s how to extract a single-quoted string (note that the<br />

regular expression is commented using the x modifier):<br />

$input =

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

Saved successfully!

Ooh no, something went wrong!