Get First N Characters of String using PHP

substr function

<?php

$text = 'HelloWorld!';
$n = 5;
$result = substr($text, 0, $n);

echo $result.PHP_EOL; // Hello

Leave a Comment

Cancel reply

Your email address will not be published.