How to get first 5 characters from string using php
$myStr = "HelloWordl";
result should be like this
$result = "Hello";
How to get first 5 characters from string using php
$myStr = "HelloWordl";
result should be like this
$result = "Hello";
An alternative way to get only one character.
You can get your result by simply use substr():
Syntax substr(string,start,length)
Example
Output :
For single-byte strings (e.g. US-ASCII, ISO 8859 family, etc.) use
substr
and for multi-byte strings (e.g. UTF-8, UTF-16, etc.) usemb_substr
:Use
substr()
:You can use the
substr
function like this:The second argument to
substr
is from what position what you want to start and third arguments is for how many characters you want to return.the substr function would do just what you want