tarun Posted August 28, 2007 Share Posted August 28, 2007 Im working on some code which searches a line of a text file to see if it matches a GET variable but only the last line can be searched Filename: test.txt Tarun Patel AnotherEg. Test !! Random Filename: readline.php <?php $path = "test.txt"; $lines = file($path); $test = $_GET["test"]; foreach($lines as $num => $val) { if ($val == $test) { echo ">> "; } echo $lines[$num]; echo "<BR>\n"; } ?> The if statement only works for the last line of "test.txt" this is because it reads the line and the break after it Eg. Line 1 would be: "Tarun " Line 2: "Patel " ETC... But the last line would be: "Random" How do I cut out the break so it only reads: "Tarun" instead of "Tarun " Quote Link to comment https://forums.phpfreaks.com/topic/67053-solved-read-lines-help/ Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 Sorry, your post is incredibly difficult to read. Whats with all the caps? I still don't see your actual question. Quote Link to comment https://forums.phpfreaks.com/topic/67053-solved-read-lines-help/#findComment-336243 Share on other sites More sharing options...
trq Posted August 28, 2007 Share Posted August 28, 2007 You might try.... if ($val == $test."\n") { Quote Link to comment https://forums.phpfreaks.com/topic/67053-solved-read-lines-help/#findComment-336244 Share on other sites More sharing options...
wildteen88 Posted August 28, 2007 Share Posted August 28, 2007 You might try.... if ($val == $test."\n") { Or use trim prehaps: if ($val == trim($test)) { trim removes all whitespace characters before and after a string. Quote Link to comment https://forums.phpfreaks.com/topic/67053-solved-read-lines-help/#findComment-336442 Share on other sites More sharing options...
tarun Posted August 29, 2007 Author Share Posted August 29, 2007 Thanks Alot Guys "Trim" Did The Trick ;D ƬӨPiiC ƧӨLVΣD ;D Quote Link to comment https://forums.phpfreaks.com/topic/67053-solved-read-lines-help/#findComment-337219 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.