1

我有两篇文章(纯文本),我希望将第一篇文章与第二篇文章匹配并突出显示匹配的数据。

设想:

ARTICLE(A)
Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来,Lorem Ipsum 一直是行业的标准虚拟文本,当时一位不知名的印刷商采用了一种类型的厨房并将其加扰以制作一本类型样本书。它不仅经历了五个世纪,而且经历了电子排版的飞跃,基本保持不变。它在 1960 年代随着包含 Lorem Ipsum passahttp://stackoverflow.com/posts/16365110/editges 的 Letraset 工作表的发布而得到普及,最近还通过 Aldus PageMaker 等桌面出版软件(包括 Lorem Ipsum 的版本)得到普及。


自 1500 年代以来的ARTICLE(B)虚拟文本。它不仅存在了五个世纪。它在 1960 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而普及

输出应该像
这样 Lorem Ipsum 只是印刷和排版行业的虚拟文本。自 1500 年代以来, Lorem Ipsum 一直是行业的标准<span class="highlight">虚拟文本</span>,当时一位不知名的印刷商采用了一种类型的厨房并将其加扰以制作类型样本书。<span class="highlight">它不仅经历了五个世纪</span>,而且经历了电子排版的飞跃,基本保持不变。<span class="highlight">它在 1960 年代随着包含 Lorem Ipsum 段落的 Letraset 表的发布而流行起来,</span>最近还随着 Aldus PageMaker 等桌面出版软件(包括 Lorem Ipsum 的版本)而普及。

注:
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

我怎样才能实现上述输出?

我希望这足够清楚。提前致谢。

4

1 回答 1

0

只需用程式化的文字在 A 中的文章 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;
?>
于 2013-05-03T18:28:10.000 回答