Re: Basic of Basics
| From: | Robert Cummings | Date: | Wed, 23 Sep 2009 01:03:00 +0000 |
| Subject: | Re: Basic of Basics | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298266@lists.php.net to get a copy of this message | ||
Todd Dunning wrote:
Rob it's LAMP php5. Godaddy virtual dedicated. I'm considering if I should just bite the bullet and attempt to build my first SQL db tonight, because there's plenty of info about doing the basics via sql. I have phpMyAdmin and cPanel. It's a classic noob issue of whether to spend extra time doing it the right way or not. Thanks very much for your interest in helping.The following will do it without a database: <?php $file = 'your-file.csv'; $keywords = 'keyword1 keyword2 ...'; $keywords = preg_split( '# +#', $keywords ); $clauses = array(); foreach( $keywords as $keyword ) {
if( ($keyword = trim( (string)$keyword )) === '' )
{
continue;
}
$keyword = escapeShellArg( $keyword );
$clauses[] = "grep -s -i -F $keyword";
}
$matches = '';
if( $clauses )
{
$file = escapeShellArg( $file );
$command = "cat $file | ".implode( " | ", $clauses );
$matches = $command;
}
echo $matches."\n";
?>
You still need to parse your feed afterwards which I presumed was a CSV or tab delimited style file WITHOUT newlines.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP