How to get the length of a string in PHP?

Member

by larissa , in category: PHP General , 2 years ago

How to get the length of a string in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 2 years 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.

Related Threads:

How to get the length of chineses string in teradata?
How to get filenames as array in string using php?
How to pass random length of a function in php?
How to strip invalid characters from a string in php?
How to get comments and string in regex?
How to get alternating characters from a string in powershell?