我有一個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