by @codeexamples

How to get first n characters from a string in PHP

Home » php » How to get first n characters from a string in PHP

To get the first n characters from a string, we can use the built-in mb_strimwidth() method in PHP.

Here is an example, that gets the first 3 characters from a following string.

<?php

echo mb_strimwidth("Ok-Google", 0, 3);

?>

Output:

Ok-