php如何在找到字符串中的内容后添加句子?
假设我有这根绳子php如何在找到字符串中的内容后添加句子?,php,str-replace,Php,Str Replace,假设我有这根绳子 $string = "While it has long been disputed, it's estimated that Julius Caesar was born in Rome on July 12 or 13, 100 BC. He hailed from Roman aristocrats[his family was far from rich]. When Caesar was 16 his father, Gaius Caesar, died.
$string = "While it has long been disputed,
it's estimated that Julius Caesar was born in
Rome on July 12 or 13, 100 BC.
He hailed from Roman aristocrats[his family was far from rich].
When Caesar was 16 his father, Gaius Caesar, died.
He remained close to his mother, Aurelia."
我想在
$string
中搜索[他的家庭远不富裕]
,并在[他的家庭远不富裕]
之后插入www.wiki.com中的新行,如果内容是静态的,并且您希望替换每次使用
也许你想要这样的东西
$string=“尽管这一问题长期以来一直存在争议,
据估计,朱利叶斯·凯撒出生于年
公元前100年7月12日或13日的罗马。
他出身于罗马贵族[他的家族远非富有]。
凯撒16岁时,他的父亲盖乌斯·凯撒去世。
他和母亲奥雷莉亚保持着亲密的关系。”
$tofind=“[他的家庭远非富有]”
$newstring=str\u replace($tofind,$tofind.“from www.wiki.com”,$string)
echo$newstring
这不是没有新行的我的答案吗?好的,你可以像这样在“from www.wiki.com”中添加标签:$newstring=str\u replace($tofind,$tofind.
from www.wiki.com,$string);
$search = '[his family was far from rich]';
echo str_replace($search, "\n" . $search . 'from www.wiki.com', $string);
$string = "While it has long been disputed,
it's estimated that Julius Caesar was born in
Rome on July 12 or 13, 100 BC.
He hailed from Roman aristocrats[his family was far from rich].
When Caesar was 16 his father, Gaius Caesar, died.
He remained close to his mother, Aurelia.";
$tofind="[his family was far from rich]";
$newstring= str_replace($tofind,$tofind." from www.wiki.com",$string);
echo $newstring;