VOOZH about

URL: https://www.geeksforgeeks.org/php/php-iconv_strlen-function/

⇱ PHP iconv_strlen() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

PHP iconv_strlen() Function

Last Updated : 9 May, 2024

The iconv_strlen() is an inbuilt function in PHP that is used to calculate the length of a string. It is very useful when your working string is encoded in a different character set, as it can accurately determine the length regardless of the encoding.

Syntax:

iconv_strlen(string $string, ?string $encoding = null) : int | false

Parameters:

  • $string: The input string from which you want to extract a portion.
  • $encoding(optional): This parameter is optional to use. If not provided it will use null.

Return Value:

The return value of the iconv_strlen() function is the length of the string. If this function fails to get the length of the string. It will return false.

Example 1: The following program demonstrates the iconv_strlen() function.


Output
String Length is = 13

Example 2: The following program demonstrate the iconv_strlen() function. In this program, we will find the length of Chinese chracter and Russian language character.


Output
Length of '你好,世界!': 6
Length of 'Привет, мир!': 12
Comment
Article Tags:
Article Tags: