csv - PHP: Filtering and posting a text file -
i have text file contains persons surname, address, time of accident , reason of accident separated white space in line. need filter file people have called in @ least 2 times same reason , echo it. i'm new php simple way. :) thank you.
edit: haven't tried since have no clue how filter file contents.
$data = array($_post['surname'], $_post['address'], $_post['time'], $_post['reason']); $info = implode(" ", $data) $info .= "\r\n"; serialize($info); file_put_contents("data.txt", $info, file_append); serialize($info);
this how wrote file. imploded file because needed make them separated 3 white spaces, no longer matters can keep array.
the expected output should this:
surname address time reason adams railroad 5 13:20 heart attack adams railroad 5 23:35 heart attack
it need repeat same people have matching surnames , reasons.
update
your text file contains string, entries seprated line brakes , values 3 spaces (actually html coded spaces).
here read whole txt file in,(some line line):
$whole_string = file_get_contents('data.txt');
so firstly each line:
$entries = explode('\n',$whole_string);
then value arrays pushed:
$whole_ar = array(); foreach($entries $e){ $whole_ar[] = explode(' ',$e); }//if 3 spaces in file in html
we get:
array( array( 'name','date','etc..' ), array( 'name2','date','etc..' ), array( 'name2','date','etc..' ) )
you store array in php file, later include('data.php');
so:
$file = '<?php $whole_ar='.var_export($whole_ar, true)."; ?>"; file_put_contents('data.php', $file);
main answer on how parse array target copies iteritating or:
$answer = array_unique(array_diff_assoc($whole_ar, array_unique( $whole_ar)));
as understand, information string when user calls in:
$newest = "huchinson estonia tallin geo street 13 2015.12.02 13:44 gas leak"
you have string in variable, stated above. explode string space characters: $data = explode(" ",$newest);
gives array number of values. first value surname , last reason of accident.
parse them out of array this: echo $data[0];//this surname
, echo end($data);//this accident type
instead of echo can assign these values variables , if surname , accident present in database:
if($saved_before == $data[0].end($data)){ echo "we working on ".end($data).", patient, dear ".$data[0]; }
p.s. dot (.) concatenating strings
Comments
Post a Comment