You are here: 'grep' a file - output to browser not working « PHP Programming Language « IT news, forums, messages
'grep' a file - output to browser not working

Posted by Phil on 10/31/07 23:45

I cannot figure why this works fine at the command-line of the linux
server, but will not output anything to the browser, and no errors in
the error_log (syslog). The goal here is to have a page to enter a
search term and grep or zgrep pattern matches in the file (will be a
log file). Probably there is a better way to do this using php, but
this is what I was able to come up with using my limited php-
knowledge. Can anyone help me debug this?

<HTML>
<HEAD>
<TITLE>Search Log</TITLE>
</HEAD>
<BODY>

<form action="<?php echo "$_SERVER[PHP_SELF]"; ?>" method="POST">
<input type="text" name="sstr" value="" size="20" maxlength="30"/>
<input type="submit" value="Search!"/>
</form>

<?php
//$test=$_POST['sstr'];
$test="foo";

if (! empty($test))
{
$cmdstr = "grep -i $test <somefile>";
$fp = popen($cmdstr, 'r');
while ($buffer = fread($fp, 8096)) {
echo "<br><hr><pre>";
print($buffer);
echo "</pre>";
flush(); }
pclose($fp);
}
else
{ echo "Please enter a search-term and try again!"; }

?>
</BODY>
</HTML>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация