Home > Article > Backend Development > How to replace the last character in php
php method to replace the last character: first create a PHP sample file; then use the regular expression "preg_replace('#.$#i', '0', $image_path);" to replace the last character of the string Just replace it.
Recommendation: "PHP Video Tutorial"
The operating environment of this tutorial: Windows 7 system, PHP version 5.6, This method works for all brands of computers.
php method to replace the last character:
PHP intercepts the last character of the string and replaces it
The code is as follows:
$image_path = 'http://www.baidu.com/1';
$str = preg_replace('#.$#i', '0', $image_path);The content to be replaced in the second parameter
Change 1 to 0
The above is the detailed content of How to replace the last character in php. For more information, please follow other related articles on the PHP Chinese website!