Date: 02/25/07 (PHP Community) Keywords: php, rss, xml, web I was wondering if there is a good place to use a php Search cardelogist.com:if (! empty($searchstr)) { // empty() is used to check if we've any search string. // If we do, call grep and display the results. echo ' '; // Call grep with case-insensitive search mode on all files $cmdstr = "grep -i $searchstr *"; $fp = popen($cmdstr, 'r'); // open the output of command as a pipe $myresult = array(); // to hold my search results while ($buffer = fgetss($fp, 4096)) { // grep returns in the format // filename: line // So, we use split() to split the data list($fname, $fline) = split(':', $buffer, 2); // we take only the first hit per file if (! defined($myresult[$fname])) { $myresult[$fname] = $fline; } } // we have results in a hash. lets walk through it and print it if (count($myresult)) { echo '
'; while (list($fname, $fline) = each ($myresult)) { echo " } echo ' '; } else { // no hits echo "Sorry. Search on $searchstr returned no results. \n"; } pclose($fp); } ?> Source: http://community.livejournal.com/php/545756.html
|