Question – How do I remove last character from a string in PHP script? In this tutorial you will learned multiple methods to remove last character from a string using php. This tutorial describes 4 methods to remove last character from a string in PHP programming language. You can use any one of the following methods as per the requirements. Don’t Miss – Check If String Contains a Sub String in PHP Method 1 – Using substr_replace function You can use the PHP substr_replace() function to remove the last character from a string in PHP. Syntax:
1 | substr_replace($string ,"", -1); |
Example:
1 2 3 4 5 6 | <?Php $string = "Hello TecAdmin!"; echo "Original string: " . $string . "\n"; echo "Updated string: " . substr_replace($string ,"",-1) . "\n"; ?> |
Output:…