Replace The Last Occurrence Of a Character With PHP

and like us on FB

In a recent project I had a need to replace the last occurrence of a character in a string with another string. While our first function works as intended, following are some others that we found on stackoverflow that also do as we intended. They’re reproduced here for your benefit and as a reference for our team.

■ ■ ■

Usage

Example:

returns: cat, dog, frog, and cow.