kerrodhall Posted December 9, 2007 Share Posted December 9, 2007 I have set up a cron job through cPanel which downloads a txt file via ftp from the following address, ftp://ftp2.bom.gov.au/anon/gen/fwo/IDQ10050.txt, to my server. I want to be able to search for the text "IDQ1005008" (without the "" marks) and then display the next few lines. e.g.: EXRACT OF TEXT FILE: ==================================================== IDQ1005007 HERBERT AND LOWER BURDEKIN DISTRICT Fine. Light to moderate E to NE winds. A moderate to high fire danger. Outlook for Monday ... Fine. Outlook for Tuesday ... Isolated showers or storms inland. IDQ1005008 TOWNSVILLE Fine. Light to moderate NE winds. MAX 32 UV INDEX - 14 [Extreme] UV Alert from 8:00 to 16:10 Outlook for Monday ... Fine. ==================================================== Search the file for the phrase IDQ1005008 (which indicates which weather district); Now I want to be able to display the 5 lines under IDQ1005008 (echo or whatever other command) as they are shown above (with the line breaks) Does anyone know how to do it? Could you please paste the code here as the last forum I posted on sent me psuedocode and I am not good with that sought of thing, I want an exact solution if possible. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
kerrodhall Posted December 9, 2007 Author Share Posted December 9, 2007 This is the code I have so far... It is not complete as it does not remove any of the other text... <? $findThis = "IDQ1005008"; $handle = @fopen("IDQ10050.txt", "r"); // Open file form read. if ($handle) { while (!feof($handle)) // Loop til end of file. { $buffer = fgets($handle, 4096); // Read a line. if ($buffer <> "IDQ1005008") // Check for string. { echo "$buffer"; // If not string show contents. } else { $buffer = $findThis; // If string, change it. echo "$buffer"; // and show changed contents. } } fclose($handle); // Close the file. } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.