首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >匹配两篇文章和高匹配数据

匹配两篇文章和高匹配数据
EN

Stack Overflow用户
提问于 2013-05-03 18:08:56
回答 1查看 67关注 0票数 1

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

场景:

文章(A)

Lorem Ipsum只是印刷和排版行业的虚拟文本。自从1500年代以来,Lorem就一直是业界标准的虚拟文本,当时一台不知名的打印机拿出一台打字机,把它拼成一本样书。它不仅活了五个世纪,而且跨越了电子排版,基本保持不变。20世纪60年代,随着包含Lorem Ipsum passahttp://stackoverflow.com/posts/16365110/editges的Lorem Ipsum passahttp://stackoverflow.com/posts/16365110/editges的发布,以及最近的包括Lorem Ipsum版本在内的桌面出版软件Aldus PageMaker的发布,它得到了广泛的推广。

(B)条

从1500年代开始就有了虚拟文本。它不仅活了五个世纪。它在20世纪60年代流行开来,发行了包含Lorem Ipsum段落的Letraset单张。

输出应该类似于这个

Lorem Ipsum只是印刷和排版行业的虚拟文本。从1500年代的<span class="highlight">开始,Lorem就一直是业界标准的</span>虚拟文本,当时一台不知名的打印机拿出一台打字机,把它拼凑成一本样书。<span class="highlight">它不仅生存了五个世纪的</span>,而且在电子排版方面的飞跃,基本上保持不变。<span class="highlight">在20世纪60年代随着包含Lorem Ipsum段落</span>的Letraset的发布而流行,最近的一款包括Lorem Ipsum版本的桌面出版软件Aldus PageMaker也是如此。

注:

array可以被看作是这样的数组

[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

如何实现上述输出?

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-03 18:28:10

只需做一个固定的str_replace文章B在A与程式化文本..。

代码语言:javascript
复制
<?
$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;
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16365110

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档