NerdConcepts Posted September 27, 2008 Share Posted September 27, 2008 Ok, what I am doing: I take a 1meg+ .html file and I insert a special tag as a file breaker. I think break apart that large HTML file in multiple parts (depending on how many work orders are actually in the file) in my test it's 43 different .html files. All this works great. This is where I do not have a clue to begin. I need to then scan a directory (the directory only has the new broken apart html files in it) and for each of those files I want to search the contents for a phrase "WORK ORDER NUMBER: " (yes a space after it) because then I want to count forward 17 characters exactly and that will give me that files work order number. From there rename the file (0.html - 43.html) to that work order number. I've search a bunch of stuff and tested a whole lot more and cannot get any of this to work. I've tried doing the search/count then rename by specific file names even and can't seem to get a grasp on it. Anyone have a clue on this? Once I can figure this out I'll be modifying the files even more but I know how to do that. the actual line of code looks like this: "Work Order: 55674999931224051</span>" even if I could just grab that whole line of code, I could then eregi_replace the "Work Order: " with nothing and the "</span>" with nothing and that would give me the Work Order Number itself. Just a thought. Still have no clue on how to locate that line, or how to "pull" it out of the html file. Here is what I am doing so far (that works). // ADD KEY TAG - WORKS $file = 'test.html'; $file_contents = file_get_contents($file); $fh = fopen($file, "w"); $file_contents = str_replace('<div class="pos" id="_0:0"','<KEYTAG><div class="pos" id="_0:0"',$file_contents); fwrite($fh, $file_contents); fclose($fh); // BREAK FILE APPART - WORKS $file_contents = file_get_contents($file); $ex = explode('<KEYTAG>',$file_contents); $ctr = 0; foreach ($ex as $x) { $file = fopen('break/' . $ctr . '.html', 'w'); $contents = $ex[$ctr]; fwrite ($file,$contents); fclose($file); $ctr++; } Link to comment https://forums.phpfreaks.com/topic/126103-file-read-and-rename-complications/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.