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-file-array-function.txt: 1104 bytes
search array by column value using in array and strpos return line and data
search delimited file ar
ray by column strpos in array search tomatos search
<?php
$file='cart-data.txt';
//return delimited
file numeric index array and search column return value or full line array
//return single value re
sult as string
$searchVal='Tomatos';
$found='';
if (file_exists($file)) {
$handle = file_get_conten
ts($file);
$complete=array();
$handle_row = explode("\n", $handle);
$rc=count($handle_row);
$i=0;
fo
reach ($handle_row as $key => $val) {
$values = explode(';', $val);
// array search
if (in_array($
searchVal,$values)) {
//return row as string uncomment
//$complete[$i] =$handle_row[$key];
//ret
urn row as array
$complete[$i] =$values;
$found='1';
}
// strpos search
if (!$found) {
foreach
($values as $k=>$v) {
if (strpos($v,$searchVal) !== false){
//return row array
$complete[
$i] =$values;
//return that field value only or specify $values['data3'];
//$complete[$i] =$va
lues[$k];
}
}
}
$i++;
}
}
echo '<pre>';
var_dump($complete);
echo '</pre>';
exit;;
?>
Post a comment
No comments yet