How to display the first characters from a string in PHP?

How to display the first characters from a string in PHP?

If you want to display the first characters from a string in PHP, use “substr”.

Check the example.

1
2
3
<html>
 
$myfile_raw = substr($myfile_raw, 0, 5000);

It will return the first 5000 characters from the string.

If you use:

2
3
4
<html>
 
$myfile_raw = substr($myfile_raw, 50, 5000);

It will echo the characters starting from 50 to 5000.

Add a comment: