liamthebof Posted August 4, 2008 Share Posted August 4, 2008 Im looking for a command, im sure there is one. I have a file with lots of lines. I need a command to search for a string and if it finds it in my file, return me the line it was found out. Is there a command / way around? Link to comment https://forums.phpfreaks.com/topic/118008-solved-looking-for-a-command/ Share on other sites More sharing options...
centerwork Posted August 4, 2008 Share Posted August 4, 2008 You may want to tray looking in at "preg-match" php function. http://us.php.net/manual/en/function.preg-match.php I know it is not much, but its a place to start. Link to comment https://forums.phpfreaks.com/topic/118008-solved-looking-for-a-command/#findComment-607059 Share on other sites More sharing options...
trq Posted August 4, 2008 Share Posted August 4, 2008 Theres always a way. <?php function findinfile($file, $search) { $file = file($file); for ($i = 0; $i < count($file); $i++) { if (strpos($file[$i], $search) !== false) { return ++$i; } } return false; } if ($found = findinfile('foo.txt','foo')) { echo "foo was found on line number $found"; } else { echo "foo was not found"; } ?> Link to comment https://forums.phpfreaks.com/topic/118008-solved-looking-for-a-command/#findComment-607060 Share on other sites More sharing options...
liamthebof Posted August 4, 2008 Author Share Posted August 4, 2008 Testing Link to comment https://forums.phpfreaks.com/topic/118008-solved-looking-for-a-command/#findComment-607069 Share on other sites More sharing options...
liamthebof Posted August 4, 2008 Author Share Posted August 4, 2008 Worked a charm. Thank you very much. Link to comment https://forums.phpfreaks.com/topic/118008-solved-looking-for-a-command/#findComment-607138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.