I have been trying to extract specific words from an array which was created from a text file using file() function in php.
The text file sample.txt is like this:
A registration has been received.
Name: test
Lastname: test2
Email: [email protected]
Company/School: Test2
Company2: test3
Address1: test4
Address2: test5
City: test6
State: test7
Country: test8
Zipcode: test9
Now I have used file() function to put this text file into an array.
$file_name='sample.txt';
$file_array=file($file_name);
Then I traversed through loop to extract each value and search for word say 'Name' from this array.
$data1='Name';
foreach($file_array as $value){
if(stripos($value,$data1)===FALSE)
echo "Not Found";
else
echo "Found";
}
But it always prints 'Not Found'. I have tried using strpos,strstr, preg_match but to no avail. Also if I use a normal array of words instead of creating from file, it works properly.
Thanks in Advance.
Update: My objective in this problem is to first detect what field it is ex. 'Name' and then its value ex. 'test'