Hack Forums
Two Docs - trying to save myself three months of work. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Computing (https://hackforums.net/forumdisplay.php?fid=88)
+---- Forum: Computing Lounge (https://hackforums.net/forumdisplay.php?fid=8)
+---- Thread: Two Docs - trying to save myself three months of work. (/showthread.php?tid=5810815)



Two Docs - trying to save myself three months of work. - Honeybun - Mar 13, 2018

Keep it short and simple.

Doc 1 is a list of names and artists, it looks like this -

[Image: MBPNt4s.png]


Doc 2 is a list of names and artists, it looks like this -

[Image: EBGQobz.png]

I need to cross reference these. If Doc 1 has something that doc 2 doesn't, I need a flag. Vice Versa.

Any way to do this? I've been doing it by hand. It's 2400 songs long and it'll take months if I don't find a work around..

note: doc 1 is also a mysql database, if that helps any.


RE: Two Docs - trying to save myself three months of work. - Nachfolger - Mar 13, 2018

Why not just run a loop against them using PHP? It won't be hard, especially if doc 2 is a text file.


RE: Two Docs - trying to save myself three months of work. - Honeybun - Mar 13, 2018

(Mar 13, 2018 08:51 AM)Nachfolger Wrote:  Why not just run a loop against them using PHP? It won't be hard, especially if doc 2 is a text file.

Not incredibly skilled with php, got a tut for something like this or some pointers?


RE: Two Docs - trying to save myself three months of work. - Nachfolger - Mar 13, 2018

(Mar 13, 2018 09:51 AM)Honeybun Wrote:  Not incredibly skilled with php, got a tut for something like this or some pointers?
Sure. Start with grabbing everything from the database, then use a loop to check if the line from the DB is in the text file.

PHP Code

<?php
// Doc 1
$doc1 = Array(); // Grab the DB lines
// Doc 2
$file = file_get_contents('somefile.txt');

// Loop through DB 
foreach($doc1 as $line) {
 
$pattern = "/^.*$pattern.*\$/m";
 if(!
preg_match_all($pattern, $file, $line)){
    echo 
"<br>Document 2 does not contain " . $line;
 }
} 
Taken and modified from https://stackoverflow.com/questions/3686177/php-to-search-within-txt-file-and-echo-the-whole-line

I'm extremely hungry and my code usually contains errors when I'm hungry so just brace for that. The concept is pretty simple, so just follow it when building the script.