Home >Backend Development >PHP Tutorial >Function of strlen function in php

Function of strlen function in php

下次还敢
下次还敢Original
2024-04-29 11:54:11632browse

strlen function returns the length of the string (number of bytes). The specific usage is as follows: strlen($string): Calculate the length of $string. For multibyte character sets, a character may consist of multiple bytes. If $string is the empty string, strlen returns 0. If $string is not a string, strlen will raise a TypeError exception.

Function of strlen function in php

strlen function

Function:
strlen function returns the length of the string (number of bytes).

Usage:

<code class="php">strlen($string);</code>

Among them, $string is the string whose length is to be calculated.

Example:

<code class="php">$string = "Hello World";
$length = strlen($string); // 11</code>

Note:

  • strlen function returns the number of bytes, not the number of characters . For multibyte character sets (such as UTF-8), a character may consist of multiple bytes.
  • If $string is an empty string, the strlen function returns 0.
  • If $string is not a string, the strlen function triggers a TypeError exception.

The above is the detailed content of Function of strlen function in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What does ul mean in phpNext article:What does ul mean in php