2013-05-03 58 views
1

我有兩篇文章(純文本),我期待匹配與第二篇文章的第一篇文章和突出顯示的匹配數據。匹配兩篇文章和highligt匹配的數據

場景:

條(A)
Lorem存有簡直是印刷排版行業的虛擬文本。 Lorem Ipsum自從16世紀以來一直是業界標準的虛擬文本,當時一臺未知的打印機採用了一種類型的廚房,並將其製作成樣本書。它不僅存活了五個世紀,而且還實現了電子排版的飛躍,基本保持不變。它在20世紀60年代隨着包含Lorem Ipsum passattp://stackoverflow.com/posts/16365110/editges的Letraset表單的發佈以及最近使用桌面出版軟件(如Aldus PageMaker,包括Lorem Ipsum版本)而得到推廣。

條(B)
虛擬文本,自從16世紀。它不僅存活了五個世紀。它推廣20世紀60年代與含Lorem存有Letraset張解除通路

輸出應該是這樣的
Lorem存有是印刷和排版行業的簡單虛擬文本。 Lorem Ipsum自從1500年代</span>以來一直是業界標準的<span class="highlight">虛擬文本,當時一臺未知的打印機採用了一種類型的廚房,並將其製作成樣本書。 <span class="highlight">它不僅存活了五個世紀</span>,而且還實現了電子排版的飛躍,基本保持不變。 <span class="highlight">它在20世紀60年代隨着包含Lorem Ipsum通道</span>的Letraset工作表的發佈以及最近使用包括版本的Lorem Ipsum的Aldus PageMaker在內的桌面出版軟件而得到了推廣。

注:
Aricle B可被視爲這樣

[0]=dummy text ever since the 1500s
[1]=It has survived not only five centuries
[2]=It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages

我怎樣才能實現上述輸出數組?

我希望這是非常明顯的。 在此先感謝。

+2

你有什麼企圖實現什麼了嗎? – 2013-05-03 18:10:24

+0

他想要顯示從第一到第二添加的內容。所以如果第二個版本的文本不同,它將被纏繞。 – 2013-05-03 18:10:59

+0

https://github.com/chrisboulton/php-diff – dm03514 2013-05-03 18:13:00

回答

0

只是做B條的定期str_replace在一個程式化的文字..

<? 
$a = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."; 

$b = array(
"dummy text ever since the 1500s", 
"It has survived not only five centuries", 
"It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages" 
); 

$h = ""; 
foreach($b as $btext) 
{ 
    $a = str_replace($btext,"<span class='highlight'>$btext</span>",$a); 
} 
echo $a; 
?>