How to get the length of a string in PHP?

Member

by larissa , in category: PHP General , a year ago

How to get the length of a string in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , a year ago

@larissa 

In PHP, you can get the length of a string using the strlen() function. Here's an example:

1
2
3
$string = "Hello, world!";
$length = strlen($string);
echo $length; // Output: 13


In the example above, the strlen() function takes the string $string as an argument and returns its length, which is then stored in the variable $length. Finally, the length is displayed using the echo statement.