PHP – Slicing Strings

Slicing

You can return a range of characters by using the substr() function.

Specify the start index and the number of characters you want to return.

Example

Start the slice at index 6 and end the slice 5 positions later:

$x = "Hello World!";
echo substr($x, 6, 5);

Note The first character has index 0.

Continue reading PHP – Slicing Strings