Php instance: processing strings byte

Source: Internet
Author: User
Problem: You need to process each byte in the string separately. for example, calculate the number of vowels contained in a string. Solution: Use the for loop to traverse every byte of a string

Problem: You need to process each byte in the string separately. for example, calculate the number of vowels contained in a string.
Solution: Use the for loop to traverse every byte of a string
Function: for (expr1; expr2; expr3)
Statement

 

$ S = 'This is my blog, lostphp ,. com '; $ num = 0; for ($ I = 0, $ j = strlen ($ s); $ I <$ j; $ I ++) {if (strpos ('aeiouaeiou ', $ s [$ I]) {$ num ++ ;}} echo $ num;

 

 

Conclusion: The first expression (expr1) is evaluated unconditionally once before the start of the loop.
Expr2 is evaluated before each cycle starts. If the value is TRUE, the loop continues and the nested loop statement is executed. If the value is FALSE, the loop is terminated.
Expr3 is evaluated (executed) after each loop ).
Each expression can be null or multiple expressions separated by commas. In expression expr2, all expressions separated by commas are calculated, but only the last result is obtained. If expr2 is null, it means an infinite loop (like C, PHP considers its value TRUE ). This may not be as useful as imagined, because it is often expected that the break statement is used to end the loop rather than the true value of the for expression.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.