• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

PHP function strlen() – Get string length

by admin

The strlen() function is used to return the length of a specific string. This function was introduced in PHP3. The strlen() function takes just one parameter (the string) and returns the number of characters in it.

Syntax:

strlen(string $string): int

Behind the scenes, strlen() actually counts the number of bytes in your string, as opposed to the number of characters. It is for this reason that multibyte strings should be measured with mb_strlen().

Parameters

Parameter Description
string The string being measured for length.

Return Values

Returns the number of characters in a string, and 0 if the string is empty.

Examples

Example 1:

print strlen("Foo") . "\n"; // 3
print strlen("Goodbye, Perl!") . "\n"; // 14

Example 2:

<?php
$text = 'aeiou';
echo strlen($text)."<br>";
$str = ' ab cd ';
echo strlen($str);
?>

The output of the above program is:

5
7

Example 3:

<?php
$str = 'abcdef';
echo strlen($str); // 6

$str = ' ab cd ';
echo strlen($str); // 7
?>

Filed Under: PHP

Some more articles you might also be interested in …

  1. PHP function strcasecmp() – Binary safe case-insensitive string comparison
  2. PHP function str_replace() – Replace all occurrences of the search string with the replacement string
  3. PHP asin function – Arc sine
  4. PHP function chop() – Alias of rtrim()
  5. PHP Function strchr() – Alias of strstr()
  6. PHP connection_status function – Returns connection status bitfield
  7. PHP cos function – Cosine
  8. PHP Function strncasecmp() – Binary safe case-insensitive string comparison of the first n characters
  9. PHP function stripslashes() – Un-quotes a quoted string
  10. PHP function convert_cyr_string() – Convert from one Cyrillic character set to another

You May Also Like

Primary Sidebar

Recent Posts

  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright