vivien
05-09-2011, 06:52 AM
:confused:just a newbie in php
this code really works, but not that exact, it can really compare word from array to per line in a file. but what im trying to do is, to compare the exact word/number.
if(strstr($line,$key))
echo $line;
if $key = 123 and line 1 is 1234 and line 2 is 123
it will still output line1
i tried to change it from if(strstr($line,$key)) to if($line == $key) and to if(strcmp($line,$key) but it still wont work
<?
$key = "waka";
$fc = file("file.txt");
$f = fopen("file.txt","r");
foreach($fc as $line)
{
if(strstr($line,$key)
echo 4line;
}
fclose($f);
?>
this code really works, but not that exact, it can really compare word from array to per line in a file. but what im trying to do is, to compare the exact word/number.
if(strstr($line,$key))
echo $line;
if $key = 123 and line 1 is 1234 and line 2 is 123
it will still output line1
i tried to change it from if(strstr($line,$key)) to if($line == $key) and to if(strcmp($line,$key) but it still wont work
<?
$key = "waka";
$fc = file("file.txt");
$f = fopen("file.txt","r");
foreach($fc as $line)
{
if(strstr($line,$key)
echo 4line;
}
fclose($f);
?>