我有一个HTML标签一个简单的文本,例如:替换文本忽略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';
请帮我找到解决办法。谢谢
所提供的例子,我不相信正则表达式可以做你想做的,因为你没有一个具体的一套规则,似乎你的要求改变与你提供的每个不同的例子。 – qJake 2012-02-22 23:01:55
好吧正则表达式不能..也许有任何其他工具?...问题是,用户(网站管理员)输入数据被替换,数组是动态的 – pleerock 2012-02-22 23:10:44
可能无法完成。除非你能澄清,如果字符串是“你好世界再次”。我想用“你好来自地球”来代替“你好世界”。输出是什么? – iWantSimpleLife 2012-02-23 01:13:55