"James Jiao" <ja*******@paradise.net.nz> wrote in message news:<ri********************@news02.tsnz.net>...
Hi, Matt
An easier way to check whether the returned value contains a carriage return
is to run this after $n=file_get_contents($filename):
echo "$n is this on the same line?";
If the string after $n wraps to a new line, then there is something wrong
with the return type. If $n does not print out anything at all, then either
the file get function is at fault or the $filename variable.
Hope this helps
==James==
"Matthew Sims" <ma**@killermookie.org> wrote in message
news:1e**************************@posting.google.c om... I see what my problem is but not sure what I need to change. I'm
reading a single number from a file that's fed into an array but the
array doesn't want to print out its output.
$oncall=array();
$oncall[1]="msims";
$oncall[2]="dtilbury";
$oncall[3]="jma";
$oncall[4]="jweaver";
$oncall[5]="cirwin";
$filename="oncall/.oncall";
$n=file_get_contents($filename);
echo "$oncall[$n]";
This prints nothing.
But when I comment out the file_get_contents and simply do $n="2" the
array prints out dtilbury like it should. My guess is the error lies
in how $n is being assigned from the file_get_contents. Any thoughts?
Much appreciation!
--Matt
Thanks for the response. I did both tests to see what $n looks like.
I did var_dump ($n) with this output:
string(2) "2 "
Is that really a space after the 2? There's no space inside the file
being read.
I did print_r ($n) with this output:
2
Can't tell if that space is there
And I also did echo "$n is this on the same line"; with this output:
2 is this on the same line
Doesn't look like the space is there
It seems $n is being assigned properly. But when I stick $n into the
$oncall array it still prints out nothing.
echo "$oncall[$n]";
Prints nothing.