Flustered Posted July 14, 2008 Share Posted July 14, 2008 I have the following start to a code that I need, I need it to read a file called modifiers.txt and return all the lines with "war between" in it, with a maximum of 10 lines returned, and reading from the latest line to the oldest. Thx all!! <?php include("config.php"); $irpg_page_title = "War Report"; include("header.php"); include("commonfunctions.php"); echo "<h1><font color=red>War Report</font></h1>\n"; -------------- code to detect trigger words from modifiers.txt and post to html if "war between" isin modifiers.txt echo line to html maximum of 10 lines ---------------------- ?> <? include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/ Share on other sites More sharing options...
Flustered Posted July 14, 2008 Author Share Posted July 14, 2008 This is an example of the line I need read.. [07/07/08 19:12:11] The war between the four parts of the realm has shown the power of the Southeast [2148/2963], whereas it led the Northeast [13/1264] to perdition. The diplomacy of the Southwest [1729/1757] and the Northwest [1248/2181] was admirable. Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-589279 Share on other sites More sharing options...
Third_Degree Posted July 14, 2008 Share Posted July 14, 2008 Directly asking for an entire code will not get you a good reputation here. But since I'm bored... Edit: Didn't see the last line of your first post... <?php $txt = fopen( "modifiers.txt", "a+" ); $lines = 0; while ( !feof( $txt ) ) { if ( ereg( "war between", fread( $txt, 512 ) ) && $lines < 10 ) { print str_replace( "war between", "<strong>war between</strong>", fread( $txt, 512 ) ) . "<br />\n"; $lines += 1; } } fclose( $txt ); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-589283 Share on other sites More sharing options...
.josh Posted July 14, 2008 Share Posted July 14, 2008 file() foreach() stripos() Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-589285 Share on other sites More sharing options...
Flustered Posted July 14, 2008 Author Share Posted July 14, 2008 I really appreciate your help, I'm very new to trying this. I tried the code below and the page opens, but very slowly. The page shows the "War Report:" , but is blank from there on. It doesn't show the results from modifiers.txt or the footer. Did I do the structure wrong or?? Thx again!! <?php include("config.php"); $irpg_page_title = "War Report"; include("header.php"); include("commonfunctions.php"); echo "<h1>War Report:</h1>\n"; $txt = fopen( "modifiers.txt", "a+" ); $lines = 0; while ( !feof( $txt ) ) { if ( ereg( "war between", fread( $txt, 512 ) ) && $lines < 10 ) { print str_replace( "war between", "<strong>war between</strong>", fread( $txt, 512 ) ) . "<br />\n"; $lines += 1; } } fclose( $txt ); ?> <? include("footer.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-589312 Share on other sites More sharing options...
Third_Degree Posted July 15, 2008 Share Posted July 15, 2008 set the permissions of modifiers.txt to 777 (Writable) Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-590174 Share on other sites More sharing options...
Third_Degree Posted July 15, 2008 Share Posted July 15, 2008 Well, just do this $txt = file( "modifiers.txt" ); $lines = 0; foreach( $txt as $line ) { if ( ereg( "war between", $line ) && $lines < 10 ) { print str_replace( "war between", "<strong>war between</strong>", $line ) . "<br />\n"; $lines += 1; } } Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-590179 Share on other sites More sharing options...
Flustered Posted July 17, 2008 Author Share Posted July 17, 2008 Thanks you very much for the help! This is showing results now, but I need it to show the results from the most recent back. It is showing the first 10 since the bot was started, so it will never change. The modifier lines are formatted like: [06/20/08 18:35:59] The war between the four parts of the realm has shown the power of the Southeast [153/361] and the Northwest [81/200], whereas it led the Northeast [0/0] and the Southwest [68/227] to perdition. [06/21/08 18:41:17] The war between the four parts of the realm has shown the power of the Northwest [304/311], whereas it led the Northeast [1/255] to perdition. The diplomacy of the Southeast [23/33] and the Southwest [99/274] was admirable. Is there a way to get it to read the date and go from the most recent backwards?? Thanks again for the help!! Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-592209 Share on other sites More sharing options...
Third_Degree Posted July 17, 2008 Share Posted July 17, 2008 change $txt = file( "modifiers.txt" ); to $txt = array_reverse( file( "modifiers.txt" ) ); Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-592226 Share on other sites More sharing options...
Flustered Posted July 17, 2008 Author Share Posted July 17, 2008 Works great, thx again!! Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-592233 Share on other sites More sharing options...
Third_Degree Posted July 18, 2008 Share Posted July 18, 2008 No Problem. Quote Link to comment https://forums.phpfreaks.com/topic/114606-solved-search-and-post-help-needed/#findComment-593082 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.