【发布时间】:2015-03-22 08:32:27
【问题描述】:
这是完美的工作:
$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_match 函数和 preg_replace。
标签: php arrays string foreach str-replace