Enter a search term check the script type and click submit. To search for a general category for example to find all results for scripts working with text files or file manipulation enter file or curl. Same for directory, sql etc. Otherwise use specific terms.
Here is the script you requested.
scripts/search-multiple-text-file-columns.txt: 1312 bytes
How to search multiple colomns of text file and return results the easy way a basic example of using
file, foreach, list, and 2 or more strpos with and / or
search text file columns return results sea
rch file easy example strpos file list foreach
search-multiple-text-file-columns.txt oct 26 13
<?ph
p
//your 2 targets to search file columns
$target1='1234';
$target2='5678';
//any delimited t
ext file
$file='myfile.data';
$lines = file($file);
$result='';
$f='';
//your file delimiter
$delimiter= ';';
if(file_exists($file)){
$lines = file($file);
if($lines){
//print_r($lin
es);
if(count($lines)>1){
//we can get result row count too
$c='0';
//foreach lines
for
each ($lines as $line){
//Set up list with variables for columns
//3 column example
//assi
gn variable to each column value
list($item_number,$item_name,$amount) = explode($delimiter, $line
);
//use AND / OR etc with 2 strpos or more
if(strpos($amount,$target1)!==false and strpos(
$item_name,$target1)!==false){
$f='1';
//got value $item_number row
$result .= $item_number."
\n";
echo $result;
$c++;
//got row count on search
echo $c."Rows";
}}}}
//no result
if(!$f){
//$result= 'not found';
echo 'not found';
echo $result;
}
}
//echo $result;
exit;
?>
Post a comment
No comments yet