Adding to an empty array if word is found in two set of texts

but how does that relate to foreach($aResult as $result):


but how does that relate to foreach($aResult as $result):

The original script required all the words saved into an array. The words could be highlighted with different colours.

Does the script now work in your browser?

yes it does. But when I change it to:

?keywords=pride,proud;kingdom;stablish; ever;throne;judgment;head;tail;peace;born;child;Philistines;David;heart;cut off;devour;destr;speak,spoke;judg;Jacob;Israel;brother; son;call;name

It doesn’t work.

Try this:

I will leave it up to your to change the hyphens to semi-colons :slight_smile:

but why replace semicolons with hyphens? Doesn’t it work as it is? I mean I used the semicolons to explode into an array.

And the reason I placed spaces in small words was so that it wouldn’t highlight them in bigger words, for example " son" and “person”.

On the other hand I don’t have any space after “child” to pick up on the mentionings of “children”.

I also don’t think think it’s turning out the way I asked. I asked for a list of words found in both texts in one array and a list of words not found in both texts in another array. HOWEVER, if a word like “pride” appears in both texts is sent to the array of words found, and “proud” isn’t found in both texts, than let it go in the array of words found along with “pride”.

I was able to write the code in the old php style except for the last part. Now that I updated to php7 I got lost.

As previously mentioned in a couple of my posts “I am confused” because I do not fully understand your requirements.

Is it possible to supply:

  1. samples of both ‘text one’ and ‘text two’ or links to the text
  2. sample search words
  3. exact required results

This may be helpful: Forum Posting Basics

Ok. Here are 2 texts. Text 1:

Isaiah 9 - Listen

Nevertheless the dimness shall not be such as was in her vexation, when
at the first he lightly afflicted the land of Zebulun and the land of
Naphtali, and afterward did more grievously afflict her by the way of
the sea, beyond Jordan, in Galilee of the nations.

The people that walked in darkness have seen a great light: they that
dwell in the land of the shadow of death, upon them hath the light

Thou hast multiplied the nation, and not increased the joy: they joy
before thee according to the joy in harvest, and as men rejoice when
they divide the spoil.

4 For thou hast broken the yoke of his burden, and the staff of his shoulder, the rod of his oppressor, as in the day of Midian.

5 For every battle of the warrior is with confused noise, and garments rolled in blood; but this shall be with burning and fuel of fire.

For unto us a child is born, unto us a son is given: and the government
shall be upon his shoulder: and his name shall be called Wonderful,
Counsellor, The mighty God, The everlasting Father, The Prince of Peace.

7 Of the increase of his government and peace there shall be no end, upon the throne of David, and upon his kingdom, to order it, and to establish it with judgment and with justice from henceforth even for ever. The zeal of the LORD of hosts will perform this.

8 The Lord sent a word into Jacob, and it hath lighted upon Israel.

9 And all the people shall know, even Ephraim and the inhabitant of Samaria, that say in the pride and stoutness of heart,

The bricks are fallen down, but we will build with hewn stones: the
sycomores are cut down, but we will change them into cedars.

11 Therefore the LORD shall set up the adversaries of Rezin against him, and join his enemies together;

12 The Syrians before, and the Philistines behind; and they shall devour Israel with open mouth. For all this his anger is not turned away, but his hand is stretched out still.

13 For the people turneth not unto him that smiteth them, neither do they seek the LORD of hosts.

14 Therefore the LORD will cut off from Israel head and tail, branch and rush, in one day.

15 The ancient and honourable, he is the head; and the prophet that teacheth lies, he is the tail.

16 For the leaders of this people cause them to err; and they that are led of them are destroyed.

17 Therefore the LORD shall have no joy in their young men, neither shall have mercy on their fatherless and widows: for every one is an hypocrite and an evildoer, and every mouth speaketh folly. For all this his anger is not turned away, but his hand is stretched out still.

For wickedness burneth as the fire: it shall devour the briers and
thorns, and shall kindle in the thickets of the forest, and they shall
mount up like the lifting up of smoke.

Through the wrath of the LORD of hosts is the land darkened, and the
people shall be as the fuel of the fire: no man shall spare his brother.

20 And he shall snatch on the right hand, and be hungry; and he shall eat on the left hand, and they shall not be satisfied: they shall eat every man the flesh of his own arm:

Manasseh, Ephraim; and Ephraim, Manasseh: and they together shall be
against Judah. For all this his anger is not turned away, but his hand is stretched out still.

2nd text:

  	1Samuel 13

1 Saul reigned one year; and when he had reigned two years over Israel,

2 Saul chose him three thousand men of Israel;
whereof two thousand were with Saul in Michmash and in mount Bethel,
and a thousand were with Jonathan in Gibeah of Benjamin: and the rest of
the people he sent every man to his tent.

3 And Jonathan smote the garrison of the Philistines that was in Geba, and the Philistines heard of it. And Saul blew the trumpet throughout all the land, saying, Let the Hebrews hear.

4 And all Israel heard say that Saul had smitten a garrison of the Philistines, and that Israel also was had in abomination with the Philistines. And the people were called together after Saul to Gilgal.

5 And the Philistines gathered themselves together to fight with Israel,
thirty thousand chariots, and six thousand horsemen, and people as the
sand which is on the sea shore in multitude: and they came up, and
pitched in Michmash, eastward from Bethaven.

6 When the men of Israel
saw that they were in a strait, (for the people were distressed,) then
the people did hide themselves in caves, and in thickets, and in rocks,
and in high places, and in pits.

And some of the Hebrews went over Jordan to the land of Gad and Gilead.
As for Saul, he was yet in Gilgal, and all the people followed him

And he tarried seven days, according to the set time that Samuel had
appointed: but Samuel came not to Gilgal; and the people were scattered
from him.

9 And Saul said, Bring hither a burnt offering to me, and peace offerings. And he offered the burnt offering.

And it came to pass, that as soon as he had made an end of offering the
burnt offering, behold, Samuel came; and Saul went out to meet him,
that he might salute him.

And Samuel said, What hast thou done? And Saul said, Because I saw that
the people were scattered from me, and that thou camest not within the
days appointed, and that the Philistines gathered themselves together at Michmash;

12 Therefore said I, The Philistines
will come down now upon me to Gilgal, and I have not made supplication
unto the LORD: I forced myself therefore, and offered a burnt offering.

And Samuel said to Saul, Thou hast done foolishly: thou hast not kept
the commandment of the LORD thy God, which he commanded thee: for now
would the LORD have established thy kingdom upon Israel for ever.

14 But now thy kingdom shall not continue: the LORD hath sought him a man after his own heart, and the LORD hath commanded him to be captain over his people, because thou hast not kept that which the LORD commanded thee.

And Samuel arose, and gat him up from Gilgal unto Gibeah of Benjamin.
And Saul numbered the people that were present with him, about six
hundred men.

16 And Saul, and Jonathan his son, and the people that were present with them, abode in Gibeah of Benjamin: but the Philistines encamped in Michmash.

17 And the spoilers came out of the camp of the Philistines in three companies: one company turned unto the way that leadeth to Ophrah, unto the land of Shual:

And another company turned the way to Bethhoron: and another company
turned to the way of the border that looketh to the valley of Zeboim
toward the wilderness.

19 Now there was no smith found throughout all the land of Israel: for the Philistines said, Lest the Hebrews make them swords or spears:

20 But all the Israelites went down to the Philistines, to sharpen every man his share, and his coulter, and his axe, and his mattock.

21 Yet they had a file for the mattocks, and for the coulters, and for the forks, and for the axes, and to sharpen the goads.

22 So it came to pass in the day of battle, that there was neither sword nor spear found in the hand of any of the people that were with Saul and Jonathan: but with Saul and with Jonathan his son was there found.

23 And the garrison of the Philistines went out to the passage of Michmash.

<p class="q">These words are found in common:<br>
<span style="font-weight: bold; color: blue">kingdom</span>, 
<span style="font-weight: bold; color: green">stablish</span>, 
<span style="font-weight: bold; color: orange"> ever</span>, 
<span style="font-weight: bold; color: darkslateblue">peace</span>, 
<span style="font-weight: bold; color: darkslategray">Philistines</span>, 
<span style="font-weight: bold; color: darkorange">heart</span>, 
<span style="font-weight: bold; color: seagreen">Israel</span> and 
<span style="font-weight: bold; color: magenta">hand</span>. 
<p class="q">These words are not found in common:<br>
<span style="font-weight: bold; color: red">pride</span>, 
<span style="font-weight: bold; color: red">proud</span>, 
<span style="font-weight: bold; color: purple">throne</span>, 
<span style="font-weight: bold; color: sienna">judgment</span>, 
<span style="font-weight: bold; color: darkolivegreen">head</span>, 
<span style="font-weight: bold; color: darkgreen">tail</span>, 
<span style="font-weight: bold; color: navy">born</span>, 
<span style="font-weight: bold; color: indigo">child</span>, 
<span style="font-weight: bold; color: darkred">David</span>, 
<span style="font-weight: bold; color: olive">cut off</span>, 
<span style="font-weight: bold; color: teal">devour</span>, 
<span style="font-weight: bold; color: slategray">destr</span>, 
<span style="font-weight: bold; color: dimgray">speak</span>, 
<span style="font-weight: bold; color: dimgray">spoke</span>, 
<span style="font-weight: bold; color: sandybrown">judg</span>, 
<span style="font-weight: bold; color: yellowgreen">Jacob</span>, 
<span style="font-weight: bold; color: mediumturquoise">brother</span>, 
<span style="font-weight: bold; color: pink">blood</span> and 
<span style="font-weight: bold; color: gray">stretch</span>. 

THe php code for the html code above is:

$colors = Array(

if( isset($_GET["keywords"]) ):
    $kw = $_GET["keywords"];

    $keywords = explode(";", $kw);
    $keyword_color = array();
    $kwNotFound = array();
    $text = "";
    for($j=0; $j < count($id); $j++){
        $text = $text.stripslashes($textData[$j]);
    $text2 = "";
    for($j=0; $j < count($id2); $j++){
        $text2 = $text2.stripslashes($textData2[$j]);

    for($i=0; $i < count($keywords);$i++){
        $keywordArr[$i] = explode(",", $keywords[$i]);
        //echo "<br />".count($keywordArr[$i]);

        for($c=0; $c < count($keywordArr[$i]);$c++){
            //echo "hiiiii".count($keywordArr[$i])."hiiiii".$keywordArr[$i][$c]."hiiii<br />\n";
            if ((preg_match("/".$keywordArr[$i][$c]."/i", $text)) && (preg_match("/".$keywordArr[$i][$c]."/i", $text2))) {
                array_push($keyword_color, array($keywordArr[$i][$c], $colors[$i]));
            } else {
                //echo $keywordArr[$c]." = not found.<br />\n";
                array_push($kwNotFound, array($keywordArr[$i][$c], $colors[$i]));
                //$kwNotFound[] = $keywordArr[$c];
    /*echo $keywordArr[0][0]."<br />\n";
    echo $keywordArr[0][1]."<br />\n";
    echo $keywordArr[1][0]."<br />\n";
    echo $keywordArr[1][1]."<br />\n";


    $kwstring = "";
    $wordsfound = "";
    for($j=0; $j < count($keyword_color);$j++){
        if($j > count($keyword_color)-2){
            $kwstring .= "<br />+ ";
            $wordsfound .= " and \n";
            //$sql9a .= " OR ";              
            //$sql9b .= " OR ";
        $kwstring .= $keyword_color[$j][0];
        //$sql9a .= "text_data LIKE '%".$keyword_color[$j][0]."%'";
        //$sql9b .= "text_data LIKE '%".$keyword_color[$j][0]."%'";        
        $wordsfound .= "<span style=\"font-weight: bold; color: ".$keyword_color[$j][1]."\">".$keyword_color[$j][0]."</span>";
        if($j < count($keyword_color)-2){
            $kwstring .= "<br />+ ";
            $wordsfound .= ", \n";
            //$sql9a .= " OR ";              
            //$sql9b .= " OR ";
    $wordsfound .= ". \n";

        //$sql9a .= ") ORDER BY id ASC";
        //$sql9b .= ") ORDER BY id ASC";
        //echo $sql9a."<br />\n";
        //echo $sql9b."<br />\n";

    $notefilename = str_replace(" ", "", strtolower("notes-".$bookTitle[0].$chapter[0]."-".$bookTitle2[0].$chapter2[0].".php"));
    //$notefilename = strtolower("notes-".$bookTitle[0].$chapter[0]."-".$bookTitle2[0].$chapter2[0].".php");
    //echo $notefilename;
    if (file_exists($notefilename)) {
        //echo "The file $filename exists";
    } else {
        //echo "The file $notefilename does not exist";

    <br />
    <br />
    <br />
    <p class="q">These words are found in common:<br />

        echo $wordsfound;
    <br />
    <br />
    <br />
    <p class="q">These words are not found in common:<br />
        for($j=0; $j < count($kwNotFound);$j++){
            if($j > count($kwNotFound)-2){
                echo " and \n";
            echo "<span style=\"font-weight: bold; color: ".$kwNotFound[$j][1]."\">".$kwNotFound[$j][0]."</span>";
            if($j < count($kwNotFound)-2){
                echo ", \n";

    echo ". \n";    

I haven’t heard from you.

I was hoping you would supply answers to my previous post.

I posted it but the moderator hasn’t approved it yet so I’m not blaming you.

1 Like

My post was hidden for the administrator’s approval.

Is it visible now? Post #63?

i don’t think so. I even forgot what I wrote. Sorry about that. I should’ve saved myself a copy.

hmmm, #63 was the only post hidden in this topic, so if it isn’t that, then I’m not sure what else to do, as either the post doesn’t exist anymore, or something else happened. Sorry. May have to provide the data @John_Betong is seeking in another post, as I don’t see anything that I can do further from the forum side. :frowning:

I’m going to have to get back to you guys. Thanks for letting me know.

I have been busy with some paid work :smile:

Check this out and let me know if there are any other problems.

I have used functions to make it more portable.

I like the 4th one:

Although if pride is found and proud isn’t found I still want proud to appear in the found list next to pride.

Try Version:005

where’s colors.php