1
votes

I have two articles ( plain text ), i am looking to match the first article with the second article and highlight the matched data.

SCENARIO:

ARTICLE(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 passahttp://stackoverflow.com/posts/16365110/editges, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

ARTICLE(B)
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

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

Note:
Aricle B can be treated as an array like this

[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

How can I achieve above output?

I hope this is clear enough. Thanks in advance.

1
Have you made any attempts to implement anything yet?Mike Brant
He wants to show what was added from the first to second. So if the text from the second version was different, it would be wrapped around.Dave Chen
How will you know how much of article B should be matched in article A? E.g: Article B has dummy text ever since the 1500s. Should it match the word dummy text alone in dummy text rest is useless if that sentence appears in Article A?raidenace
you can consider article B as an 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 passagesAdnan

1 Answers

0
votes

Just do a regular str_replace of article B in A with stylized text..

<?
$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;
?>