PHP Questions Home

Categories

Arrays
Files
Forms
Functions
Images
MySQL
Numbers
Others
Strings
Website


PHP Functions

PHP Functions


More PHP

Top Questions
Ask a Question

How do I find the length of a string in PHP?


An extremely common thing to want to do in PHP is to find the length of a string. This may be for a variety of reasons, such as ensuring that the user has entered data of a sensible length into a form field (e.g. if their name is one letter long then there is probably something weird going on).

Here is a simple example of how this works:

<?php

$data 
"hello world";
echo 
strlen($data); //11
?>


And that's all there is to it - simple but very well worth knowing because it is something that you'll need to know time and time again.



More strings PHP Questions

How do I print text to the screen?
How do I fetch the meta tags from a webpage using PHP?
How do I calculate the metaphone of a string?
How do I turn a string into an array?
How do I display newline characters on a webpage?