Home  »  CodeGuidesProgrammingSnippetsTechnology   »   PHP Replace Last Character in String

PHP Replace Last Character in String

Posted: September 11, 2022 | by Michael Bright

This PHP replace last character in string example using substr:

$string = substr($string, 0, -1);

Remove last character from string if character is known using rtrim:

$sourcestr = "Remove the comma from end of this string,";

$string = rtrim($arraynama, ",");

// Output
// Remove the comma from end of this string

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.