I am pulling lines from a text file based on a search key. Below is a sample of the pipe delimited file... and the script I'm not using. I am wanting to display the total count of subscribers (in this case, 2) that I find based on the key. Have any idea how I would do that???? Thanks for your help!
text.txt
John|Doe|nonsubscriber
Betty|Dilly|subscriber
John|Smith|nonsubscriber
Ben|Wilson|subscriber
<?php
$key = "subscriber"
$data = file("text.txt");
foreach ($data as $line_num => $line)
{
$fields = explode('|', $line);
if (preg_match('/' . preg_quote($key,'/') . '/', $fields[2]))
echo "$fields[0] $fields[1] $fields[2]";
}
?>