あなたは、このいずれかのfopen
とfread
またはfile
を使用することができます。個人的には、これはかなり小さいファイルで始まるように私はファイルを選択します。良い測定のために
$row = -1;
$fl = file('/path/to/file');
if($fl)
{
foreach($fl as $i => $line)
{
// break the line in two. This can also be done through subst, but when
// the contents of the string are this simple, explode works just fine.
$pieces = explode(", ", $line);
if($pieces[ 1 ] == $name)
{
$row = $i;
break;
}
}
// $row is now the index of the row that the user is on.
// or it is -1.
}
else
{
// do something to handle inability to read file.
}
、fopenのアプローチ:
// create the file resource (or return false)
$fl = fopen('/path/to/file', 'r');
if(!$fl) echo 'error'; /* handle error */
$row = -1;
// reads the file line by line.
while($line = fread($fl))
{
// recognize this?
$pieces = explode(", ", $line);
if($pieces[ 1 ] == $name)
{
// ftell returns the current line number.
$row = ftell($fl);
break;
}
}
// yada yada yada
あなたの自己を大いに好んで、データベースを使用し始める –