11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

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

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

www.it-ebooks.infoCHAPTER 9 • STRINGS AND REGULAR EXPRESSIONSBecause the provided username is not all lowercase, ereg() will not return FALSE (instead returningthe length of the matched string, which <strong>PHP</strong> will treat as TRUE), causing the error message to output.The optional input parameter regs contains an array of all matched expressions that are grouped byparentheses in the regular expression. Making use of this array, you could segment a URL into severalpieces, as shown here:echo $regs[0];echo "";echo $regs[1];echo "";echo $regs[2];echo "";echo $regs[3];// outputs the entire string "http://www.apress.com"// outputs "http://www"// outputs "apress"// outputs "com"This returns the following:http://www.apress.comhttp://wwwapresscomPerforming a Case-Insensitive SearchThe eregi() function searches a string for a defined pattern in a case-insensitive fashion. Its prototypefollows:int eregi(string pattern, string string, [array regs])This function can be useful when checking the validity of strings, such as passwords. This concept isillustrated in the following example:195

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

Saved successfully!

Ooh no, something went wrong!