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

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

1
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.

2
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
shined.

3
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.

6
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,

10
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.

18
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.

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

21
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
   
  
  	-->
   - 
  
  	Listen
   - 
  
  	Go

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.

7
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
trembling.

8
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.

10
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.

11
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.

13
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.

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

18
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>
<br>
<br>
<br>
<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>. 
</p>

THe php code for the html code above is:

<?php
$colors = Array(
"red",
"blue",
"green",
"orange",
"purple",
"sienna",
"darkolivegreen",
"darkgreen",
"darkslateblue",
"navy",
"indigo",
"darkslategray",
"darkred",
"darkorange",
"olive",
"teal",
"slategray",
"dimgray",
"sandybrown",
"yellowgreen",
"seagreen",
"mediumturquoise",
"pink",
"gray",
"magenta",
"lime",
"cyan",
"deepskyblue",
"darkorchid",
"silver",
"paleturquoise",
"wheat",
"palegreen",
"lightblue",
"plum",
"black",
"#741b47",
"#351c75",
"#0b5394",
"#134f5c",
"#38761d",
"#bf9000",
"#b45f06",
"#990000",
"#a64d79",
"#674ea7",
"#3d85c6",
"#45818e",
"#6aa84f",
"#e69138",
"#cc0000",
"#c27ba0",
"#8e7cc3",
"#6fa8dc",
"#76a5af",
"#93c47d",
"#f6b26b",
"#e06666",
"#d5a6bd",
"#b4a7d6",
"#9fc5e8",
"#a2c4c9",
"#b6d7a8",
"#f9cb9c",
"#ea9999"
);

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

    $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]);
        //print_r($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";

    var_dump($keywordArr);*/

    $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";
        include($notefilename);
    } else {
        //echo "The file $notefilename does not exist";
    }

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

        echo $wordsfound;
    ?>
    </p>
    <br />
    <br />
    <br />
    <p class="q">These words are not found in common:<br />
    <?php 
        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";    
    ?>
    </p>

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.

http://www.johns-jokes.com/downloads/sp-f/gilgalbiblewheel/

I have used functions to make it more portable.

I like the 4th one:
http://www.johns-jokes.com/downloads/sp-f/gilgalbiblewheel/index-jb-004.php

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

@gilgalbiblewheel

where’s colors.php

I was in a hurry because I was late visiting a friend.

I missed passing the “found words” to the function that adds the colours. It will be tomorrow before I am back on the desktop to make the changes.

Is the “pride” and “proud” working correctly?

I added pride in one of the texts and noticed it didn’t work. I blocked colors.php for now.

I have updated the Online Demo

Colours now work and also “proud”.

Please try the new functions in your script that “didn’t work.”

but where is colors.php?

View the source or search for “colors.php” and you will see the following:

require ‘colors.php’;

The file was supplied by yourself in post #64