3

This is working perfectly :

$replaceLyrics=str_replace
(
    'story',
    '_____',
    'The story of my life I take her home I drive all night to keep her warm and time Is frozen (the story of, the story of)'
);

echo $replaceLyrics;

output :

The _____ of my life I take her home I drive all night to keep her warm and time Is frozen (the _____ of, the _____ of)

My question is if it's possible to use internal php funtion to replace only the first occurrence from matches and not all of them.

I'm expecting to get this output :

The _____ of my life I take her home I drive all night to keep her warm and time Is frozen (the story of, the story of)
davidmarko
  • 343
  • 3
  • 17

1 Answers1

5

This could be done using preg_replace.

<?
$str = 'story story story';
echo preg_replace('/story/', '___', $str, 1);
oshell
  • 8,923
  • 1
  • 29
  • 47