Remove Last N Characters from String using PHP

substr function

<?php

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

echo $result; // Hello

Leave a Comment

Cancel reply

Your email address will not be published.