Elegant PHP solution to replace a specific substring
<p>There is the string</p>

<p>"a cat is a cat, but a dog is not a cat"</p>

<p>I wish to replace only the second "cat" substring with another word, preferably using native php functions. The solution must be general, for example to be able to replace the first 'cat' string or the third.</p>

<p>Oh well, maybe somebody will find this and realise the complexity of the problem and reopen it again.</p>
