Skrev ihop något..
Scriptet kollar om söksträngen matchar för- och efternamn.
Kod:
<?php
$file = 'file.txt';
$search = 'Johanna';
/* --------------------- */
$fp = @fopen($file, 'r') or die('Filen kunde inte läsas in');
$contents = NULL;
$result = array();
if(is_resource($fp)){
while( ! feof($fp)) {
$contents .= fgets($fp);
}
$lines = explode("\n", $contents);
for($i = 0; $i < count($lines); $i++){
$person = explode(' ', $lines[$i]);
if((stripos($person[0], $search) !== FALSE) OR (stripos($person[1], $search) !== FALSE)){
echo $lines[$i] . '<br />' . PHP_EOL;
}
}
} else {
echo 'Något gick snett..';
}