By default, the PHP function preg_replace finds and replaces ALL matched occurrences. How to make it ONLY replace the FIRST match?

There's a parameter to do that.

Just use it like this:

PHP Code:
preg_replace($search$replace$subject1); 
The 4th parameter is the key, which tells preg_replace to only do replacement for the first match.