Just an hour or so ago, Ron Piggot asked a question on the PHP General mailing list. The original question was how he could replace a single matching character in a string containing multiple matches with another random character. I mocked up a working example in about five minutes or so. It’s far from perfect, and not very elegant, but it’ll work as a starting point of reference.
The code I sent back in reply follows: