Home  »  CodeGuidesProgrammingSnippetsTechnology   »   PHP Replace Last Character in String

PHP Replace Last Character in String

Posted: September 11, 2022 | by Site Host

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.

Share it!

See also  How to set the JSON Header in PHP