-1

I have a text like this:

Paul loves Anna, Anna loves John, and John loves Betty. Unluckily, Betty loves Paul. Paul now hates Anna because she loves John. But John loves Betty, and that's why Anna is sad. Now Anna would like to marry Paul, but it's too late.

and I need to replace the first occurrence of each name. Do I need to use preg_replace_callback? Is there any simpler solution?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156

1 Answers1

1

preg_replace (as well as preg_replace_callback) accept a parameter to limit the number of time it replaces something.

http://php.net/manual/en/function.preg-replace.php

i'm not good with patterns but you should be able to figure the pattern and then use something like

preg_replace($patterns, "", $string, 1);

i can't see how more simple it can get

Louis Loudog Trottier
  • 1,367
  • 13
  • 26