Detecting changes in an external file

4 replies
Hello all,

I am helping a friend out with a rather large project and it involves taking these seemingly small files(under 10 mb) reading them in and then manipulating them using php with the overall goal to dump variables and so on into xml templates.

I can use php and regex to pick apart individual lines but where I seem to be hitting a brick wall is in detecting a change in the external file.

This friend has an archaic way of archiving/cataloging various newspapers in the bay area and is trying to move it from flat file(archaic notes/symbols, etc) to a relational DB.

We are wanting to read in a file, have it check for lines starting with [TAB] and [start box boh1]. As it sits we can parse out the box code from a [start box boh1] leaving just boh1. What I have loosely coded is a while loop to say that while box code = boh1 append each line starting with [TAB] with boh1. So what I am asking is am I going about this in the right way? Heres the code I have so far...

Any assistance is greatly appreciated.

PHP Code:
$bc "[start box BOH1]";
$bc1 str_replace("[start box ","",$bc);
$box substr($bc1,0,strlen($bc1)-1);
echo 
"<br />".$box;
while(
$bc "[start box BOH1]"){
    
// newline variable .=" ".$box;
    

Jay
#detecting #external #file
  • Profile picture of the author sdwrage
    An easier way may be to check the date modified. Maybe store the date in a database to test against or even a flat file would work.

    filemtime("myuberawesomefile.php");

    php.net/filemtime (sorry for no link... I only have 3 posts so far )
    {{ DiscussionBoard.errors[2350145].message }}
  • Profile picture of the author jaybaker
    I think you are missing the point. We need to try and determine if / when a box starts and ends as well as individual issue lines in this flat file... If the box starts with BOH1 then when it gets to [end box boh1] it adds the boh1 variable to the end of each line... Any assistance is greatly appreciated.

    Jay
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[2354557].message }}
    • Profile picture of the author nmarley
      Originally Posted by jaybaker

      I think you are missing the point.
      Umm... you said above "...where I seem to be hitting a brick wall is in detecting a change in the external file". Perhaps you're not communicating the point clearly.

      I would recommend using preg_replace in place of str_replace, and use a line start anchor (^) in your pattern.

      I'm also a little confused as to what you're trying to accomplish. You're looking for lines that start with [TAB] AND that start with [start box boh1]?

      Then you would use a pattern like "^(([TAB])|([start box boh1]))".

      I'm also confused as to whether you are looking for a literal tab char or for the string "[TAB]".
      {{ DiscussionBoard.errors[2354751].message }}
  • Profile picture of the author jaybaker
    Ok First off I am looking for the tab as in [TAB] not the literal tab character.

    Next what I am trying to do is append the box code boh1 to the end of each line that starts off with [TAB]

    Thanks for your reply.
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[2407507].message }}

Trending Topics