How to query the string length in php

coldplay.xixi
Release: 2023-03-03 20:20:01
Original
11479 people have browsed it

How to query the string length in php: first create a new php file and define two strings in the file; then create a new [utf8_strlen()] function and use the [preg_match_all()] method to pass the regular expression Split the string; finally use echo to output the results to the page.

How to query the string length in php

How to query the string length in php:

1. First, create a new php file and name it test. php.

How to query the string length in php

Related learning recommendations: php graphic tutorial

2. In test.php In the file, two strings are defined, a pure English string and the other a mixed Chinese and English string.

How to query the string length in php

3. Use the strlen() method to count the length. It can be seen from the execution program results that the strlen() method counts the string length of $Str1 correctly. The second one is counted. The length of string $Str2 is wrong.

How to query the string length in php

4. Create a new utf8_strlen() function and define its parameter as $string, which defaults to null.

How to query the string length in php

5. Within the utf8_strlen() function, use the preg_match_all() method to split the string through regular expressions and save it in the $match variable. Finally, pass count () method counts the number of array elements obtained and returns the result.

How to query the string length in php

6. Use the utf8_strlen() method to count the lengths of $Str1 and $Str2 strings respectively, and use echo to output the results to the page.

How to query the string length in php

#7. Run the test.php file in the browser and check the results of the program execution. From the two results, it can be seen that the length of the statistical string has been successfully achieved.

How to query the string length in php

Related video recommendations: PHP programming from entry to proficiency

The above is the detailed content of How to query the string length in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template