I need to read from either an array or a file (preferably a file so it’d be easy to update) which contains acronyms and synonyms of common words and use that to find and replace in a string. For example, say CBN stands for “Cannot Be Negated”. I need to replace “CBN king” with “Cannot Be Negated king”. How can i do this in PHP?
Share
You could use an INI file to store your translation table like so (translate.ini):
Read the file into an array like so:
Replace all acronyms with their full versions:
(Please note the use if str_ireplace() to avoid case issues).