Skip to content
Advertisement

Issue with str_replace replacing the wrong values

I’m trying to replace a list of numbers (ids) with their related title, the problem is that when the title has a number also gets replaced, for example:

JavaScript

Wrong current result:

JavaScript

Should be:

JavaScript

What would be a better way to do this?

Advertisement

Answer

Try strtr instead str_replace:

JavaScript

Result:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement