Home > Backend Development > PHP Problem > How to determine how many characters there are in a string in php

How to determine how many characters there are in a string in php

青灯夜游
Release: 2023-03-15 20:24:02
Original
2904 people have browsed it

Judgment method: 1. Use the "str_split($str)" statement to convert the string into a character array; 2. Use the "array_unique($arr)" statement to remove duplicate characters in the array; 3. Use " The count (duplication-removed array)" statement counts the length of the array after the duplication is removed, and you can obtain the number of different characters.

How to determine how many characters there are in a string in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php determines how many characters there are in the string , which is to determine which different characters are in the string. Let me introduce to you the judgment method below.

Implementation method:

1. Use the str_split() function to convert the string into a character array

<?php   
$str = &#39;absd346d182831&#39;;
$arr=str_split($str);
var_dump($arr);
?>
Copy after login

How to determine how many characters there are in a string in php

2. Use the array_unique() function to remove repeated characters

$newarr=array_unique($arr);
var_dump($newarr);
Copy after login

How to determine how many characters there are in a string in php

will return a new array, the key value of which is the non-repeating characters in the string .

3. Use the count() function to count the length of the array after deduplication, and you can know the number of different characters in the string.

echo count($newarr);
Copy after login

How to determine how many characters there are in a string in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to determine how many characters there are in a string 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