Try the common syntax instead:
if (strlen($message)<140) {
echo "less than 140";
}
else
if (strlen($message)>140) {
echo "more than 140";
}
else {
echo "exactly 140";
}
Answer from nicola on Stack OverflowPHP
php.net › manual › en › function.strlen.php
PHP: strlen - Manual
In PHP, a null byte in a string does NOT count as the end of the string, and any null bytes are included in the length of the string. For example, in PHP: strlen( "te\0st" ) = 5 In C, the same call would return 2.
W3Schools
w3schools.com › php › func_string_strlen.asp
PHP strlen() Function
zip_close() zip_entry_close() ... zip_entry_read() zip_open() zip_read() PHP Timezones ... The strlen() function returns the length of a string....
How to find string length in php with out using strlen()? - Stack Overflow
How can you find the length of a string in php with out using strlen() ? More on stackoverflow.com
How do you handle long strings in respect to the 120 char limit in PSR-2?
I go one of two ways:
-
HEREDOC isn't that bad, the indenting thing is a pain but not that much of one. This is usually what I do for strings with significant line breaks (like SQL statements).
-
Fuck line lengths and just have one long string. It's 2015, we're not on TRS-80s anymore. This is what I do most of the time.
The state of PHP unicode in 2019
PHP doesn't really manage unicode at all. They tried, and that was one of the factors that led to PHP 6 never becoming a thing. So instead, they decided to not have unicode strings at all - you only get byte arrays (which you may write as string literals). If you want actual strings, you have to implement most of it yourself, PHP only gives you a couple of primitives that you can use to operate on various string encodings (including utf-8 and other Unicode encodings) at the byte array level. So basically much the same deal as in C, except that PHP is supposed to be a high-level programming language that takes care of these things for you. More on reddit.com
How to remove numbers from end of the string
howdy jishnutp, this seems to do the job ... PM(.*)\d{1,}$ it finds PM and any final digits, then grabs anything between them. it works with your data set on regex101.com if you enable "multiline". take care, lee More on reddit.com
06:51
PHP String Functions | Length, Count Words, Reverse, Search, Replace ...
03:50
PHP String Functions for Beginners: Length & Case Manipulation ...
07:44
How to Determine String Length in PHP - YouTube
05:09
Beginner PHP Tutorial - 46 - String Functions: String Length - YouTube
12:02
PHP & MySQL Tutorial 18 - String length (strlen) function and string ...
10:13
PHP string Length and count function | PHP tutorial for beginners ...
Top answer 1 of 6
89
Try the common syntax instead:
if (strlen($message)<140) {
echo "less than 140";
}
else
if (strlen($message)>140) {
echo "more than 140";
}
else {
echo "exactly 140";
}
2 of 6
12
[0]=> string(141) means $message is an array so you should do strlen($message[0]) < 141 ...
ReqBin
reqbin.com › code › php › 8ob9jfdb › php-string-length-example
How can I get the length of a string in PHP?
To find the length of a PHP string, you can use the built-in strlen() function.
W3Schools
w3schools.com › php › php_string.asp
PHP Strings
In PHP, strings are surrounded by either double quotes, or single quotes. ... Note: There is a difference between double quotes and single quotes in PHP. You can use double or single quotes, but you should be aware of the differences between the two.
Reintech
reintech.io › blog › phps-strlen-function-practical-guide-measuring-string-length
PHP's `strlen()` Function: A Practical Guide for Measuring String Length
The strlen() function is a fundamental PHP string manipulation tool that returns the number of bytes in a string.
Top answer 1 of 16
14
I know this is a pretty old issue, but this piece of code worked for me.
$s = 'string';
$i=0;
while ($s[$i] != '') {
$i++;
}
print $i;
2 of 16
7
$inputstring="abcd";
$tmp = ''; $i = 0;
while (isset($inputstring[$i])){
$tmp .= $inputstring[$i];
$i++;
}
echo $i; //final string count
echo $tmp; // Read string
while - Iterate the string character 1 by 1
$i - gives the final count of string.
isset($inputstring[$i]) - check character exist(null) or not.
Functions-Online
functions-online.com › strlen.html
test strlen online - PHP string functions - functions-online
The function strlen() returns the length of the given $string. ... @mjb4: the charset is a general problem. PHP uses ISO, this site UTF-8.
Tutorialspoint
tutorialspoint.com › php › php_function_strlen.htm
PHP - strlen() Function
It returns the length of the given string − · <?php $str = "Hello from TP"; echo "The given string: $str"; echo "\nThe length of the given string: "; #using strlen() function echo strlen($str); ?>
Tutorials Class
tutorialsclass.com › home › faqs › career › how to find string length in php?
How to find String Length in PHP? - FAQs - Tutorials Class
April 27, 2020 - The PHP strlen() function returns the length of a string. String length count will include space & special characters as well. See example here
GeeksforGeeks
geeksforgeeks.org › php › how-to-get-string-length-in-php
How to get String Length in PHP ? - GeeksforGeeks
July 23, 2025 - ... <?php // PHP program to count all // characters in a string $str = "GeeksforGeekslover"; // Using strlen() function to // get the length of string $len = strlen($str); // Printing the result echo $len; ?>