Let me admit right up front this is my first foray into php. I'm trying
to simply use a small data file to populate a page. I'm using the
file() function but I want my "data records" to be seperated by a double
\n.
My problem is I can't seem to compare a line to anything. My first
problem was determining the end of a data block, finding the double
newline. But in frustration, I just tried to compare a line to a known
value and I still can't compare strings correctly.
Here's a sample data file,
-----------
N2325N
Piper Tomahawk
N2378K
Piper Tomahawk
N11242
Cessna 150
N68440
Cessna 152
----------------------
btw, I even tried '*' chars between lines and couldn't match them
correctly.
Here's what I'm trying to do,
function getNextDataBloc k() {
global $data;
$blk = array();
$line = array_shift($da ta);
while ($line <> "") {
array_push($blk , $line);
$line = array_shift($da ta);
}
return $blk;
}
$dataBlock = getNextDataBloc k();
echo $dataBlock;
Here's what it's become,
function getNextDataBloc k() {
global $data;
$blk = array();
//echo "<br />data ==>"; print_r($data);
//echo "<br />blk ==>"; print_r($blk);
$line = array_shift($da ta);
while ($line <> "") {
echo "<br />+$line";
if ($line == "") print("nothing" );
if ($line == " ") print("space");
if ($line == "*") print("star");
if ($line == "N2378K") print("tailnumb er");
array_push($blk , $line);
//echo "<br />blk ==>"; print_r($blk);
$line = array_shift($da ta);
rtrim($line);
echo "<br /><br />getting new line ==> [$line]";
}
//echo '<br />looking in blk ==>'; print_r($blk);
return $blk;
}
//$data[3] = "";
$dataBlock = getNextDataBloc k();
echo $dataBlock;
Even when I know a line, like trying to match a known tailnumber,
N2378K, the line doesn't fire!
Thanks for any help. I'm open to completely new ideas on how to read in
this small data file and strip off one block of data at a time but I'd
also like to understand why I can't find newlines. I've tried
everything, comparing for "\n", x32 actually show up on the web page so
I tried searching for a space, nothing. I can't kill the loop on an
empty line.
Many thanks,
/jim
to simply use a small data file to populate a page. I'm using the
file() function but I want my "data records" to be seperated by a double
\n.
My problem is I can't seem to compare a line to anything. My first
problem was determining the end of a data block, finding the double
newline. But in frustration, I just tried to compare a line to a known
value and I still can't compare strings correctly.
Here's a sample data file,
-----------
N2325N
Piper Tomahawk
N2378K
Piper Tomahawk
N11242
Cessna 150
N68440
Cessna 152
----------------------
btw, I even tried '*' chars between lines and couldn't match them
correctly.
Here's what I'm trying to do,
function getNextDataBloc k() {
global $data;
$blk = array();
$line = array_shift($da ta);
while ($line <> "") {
array_push($blk , $line);
$line = array_shift($da ta);
}
return $blk;
}
$dataBlock = getNextDataBloc k();
echo $dataBlock;
Here's what it's become,
function getNextDataBloc k() {
global $data;
$blk = array();
//echo "<br />data ==>"; print_r($data);
//echo "<br />blk ==>"; print_r($blk);
$line = array_shift($da ta);
while ($line <> "") {
echo "<br />+$line";
if ($line == "") print("nothing" );
if ($line == " ") print("space");
if ($line == "*") print("star");
if ($line == "N2378K") print("tailnumb er");
array_push($blk , $line);
//echo "<br />blk ==>"; print_r($blk);
$line = array_shift($da ta);
rtrim($line);
echo "<br /><br />getting new line ==> [$line]";
}
//echo '<br />looking in blk ==>'; print_r($blk);
return $blk;
}
//$data[3] = "";
$dataBlock = getNextDataBloc k();
echo $dataBlock;
Even when I know a line, like trying to match a known tailnumber,
N2378K, the line doesn't fire!
Thanks for any help. I'm open to completely new ideas on how to read in
this small data file and strip off one block of data at a time but I'd
also like to understand why I can't find newlines. I've tried
everything, comparing for "\n", x32 actually show up on the web page so
I tried searching for a space, nothing. I can't kill the loop on an
empty line.
Many thanks,
/jim
Comment