我有一段带有HTML标签的简单文本,例如:
Once <u>the</u> activity <a href="#">reaches</a> the resumed state, you can freely add and remove fragments to the activity. Thus, <i>only</i> while the activity is in the resumed state can the <b>lifecycle</b> of a <hr/> fragment change independently.
当我替换文本内容时,需要忽略其中的HTML标签,例如这段字符串:Thus, <i>only</i> while
,我需要替换成:Hello, <i>its only</i> while
,待替换的文本和字符串是动态的。我需要你帮我构建preg_replace模式。
$text = '<b>Some html</b> tags with <u>and</u> there are a lot of tags <i>in</i> this text';
$arrayKeys= array('Some html' => 'My html', 'and there' => 'is there', 'in this text' => 'in this code');
foreach ($arrayKeys as $key => $value)
$text = preg_replace('...$key...', '...$value...', $text);
echo $text; // output should be: <b>My html</b> tags with <u>is</u> there are a lot of tags <i>in</i> this code';
请帮我找到解决方案。谢谢。