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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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 str_repeat() – Repeat a string
  2. PHP Function strchr() – Alias of strstr()
  3. PHP cos function – Cosine
  4. PHP addslashes function – Quote string with slashes
  5. PHP function chop() – Alias of rtrim()
  6. PHP asin function – Arc sine
  7. PHP atanh function – Inverse hyperbolic tangent
  8. How to test a PHP script
  9. PHP bindec function – Convert a number between arbitrary bases
  10. “Access denied for user ‘username’@’hostname’ (using password: YES)” – Error while connecting MySQL with PHP

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright