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.

CHAPTER 9 • STRINGS AND REGULAR EXPRESSIONSwww.it-ebooks.info?>if (! strcasecmp($email1, $email2))echo "The email addresses are identical!";In this example, the message is output because strcasecmp() performs a case-insensitivecomparison of $email1 and $email2 and determines that they are indeed identical.Calculating the Similarity Between Two StringsThe strspn() function returns the length of the first segment in a string containing characters also foundin another string. Its prototype follows:int strspn(string str1, string str2 [, int start [, int length]])Here’s how you might use strspn() to ensure that a password does not consist solely of numbers:In this case, the error message is returned because $password does indeed consist solely of digits.You can use the optional start parameter to define a starting position within the string other thanthe default 0 offset. The optional length parameter can be used to define the length of str1 string thatwill be used in the comparison.Calculating the Difference Between Two StringsThe strcspn() function returns the length of the first segment of a string containing characters notfound in another string. The optional start and length parameters behave in the same fashion as thoseused in the previously introduced strspn() function. Its prototype follows:int strcspn(string str1, string str2 [, int start [, int length]])Here’s an example of password validation using strcspn():In this case, the error message will not be displayed because $password does not consist solely ofnumbers.208s

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

Saved successfully!

Ooh no, something went wrong!