This question already has an answer here:
i wondering why substr function count space Example:
$text= 'Hello World';
echo substr($text,0,6);
the output will be
Hello
but i want to be
Hello w
Thanks for any help
</div>
The substr()
function counts from the first character as 0
and this includes the space as well.
This should give your desired output:
$text= 'Hello World';
echo substr($text,0,7);
A space character is counted just like any other character. To get the output you want you need to use:
$text= 'Hello World';
echo substr($text,0,7);