这是完美的工作:
$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;
输出 :
The _____ of my life I take her home I drive all night to keep her warm and time Is frozen (the _____ of, the _____ of)
我的问题是,是否有可能使用内部php函数替换匹配中的第一个匹配项,而不是全部替换。
我期望得到这个输出:
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)
可以使用preg_replace来完成。
<?
$str = 'story story story';
echo preg_replace('/story/', '___', $str, 1);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句