LMarie Posted August 31, 2009 Share Posted August 31, 2009 Need help finding specific contents in a file (test.txt) and printing only the lines that contains this information. what iv got so far (iv marked where i have issues with #) <?php $fil = fopen('/home/www/test.txt', 'r'); while (!feof($fil)) { $line = fgets($fil); #each line in the file contains 8 fields, separated by :: example: 301::fshsfs::fsrsyshs:ofjfghdysb::5372928230) #if the line contains 301 in the first field then echo $line; else echo 'not available!'; } fclose($fil); ?> i want the result to be displayed in a table too :S Link to comment https://forums.phpfreaks.com/topic/172563-php-search-for-specific-lines-and-display-in-table/ Share on other sites More sharing options...
Garethp Posted August 31, 2009 Share Posted August 31, 2009 if(preg_match('~^301::~', $line)) { echo "<tr><td>$line</td></tr>"; } Ofcourse, don't forget to open and close the table before and after Link to comment https://forums.phpfreaks.com/topic/172563-php-search-for-specific-lines-and-display-in-table/#findComment-909703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.