Để xóa ký tự đầu tiên của một chuỗi trong PHP, mã như sau:
Ví dụ
<?php
$str = "Test";
echo "Before removing the first character = ".$str;
$res = substr($str, 1);
echo "\nAfter removing the first character = ".$res;
?>
Kết quả
Điều này sẽ tạo ra kết quả sau:
Before removing the first character = Test After removing the first character = est
Ví dụ
Hãy xem một ví dụ khác:
<?php
$str = "Demo";
echo "Before removing the first character = ".$str;
$res = ltrim($str, 'D');
echo "\nAfter removing the first character = ".$res;
?>
Kết quả
Điều này sẽ tạo ra kết quả sau:
Before removing the first character = Demo After removing the first character = emo