[php]$team_array(substr($filename, 5, 2))[/php]
Not a function. Adding parentheses makes the engine think it is a function. Access array indices with brackets [].
[php]$team_array(substr($filename, 5, 2))[/php]
Not a function. Adding parentheses makes the engine think it is a function. Access array indices with brackets [].
And using substr($filename, 5, 2) WILL cause issues. It is only going to work for Team10 to Team99, before or after and you are grabbing something else.
Fixing the () issue created another when inputting the entire array…
The problem happens when I put in “6” => “Florida State”,
Parse error: syntax error, unexpected '", ’ (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /home/content/29/8946729/html/NCFA.php on line 614
When I remove it the page comes back and the time stamps appear but all of the filenames disappear.
Well, Rob, you mixed in two different codes. One from me and one from Astonecipher… Always dangerous
to mix your drinks… LOL
So, to fix this, earlier on, we were using the filenames to get the legend number from. For that, you had some
names like Team86.coa And, for that array, we needed to strip out the number and to do that we used the
substr($filename, 5, 2) which would give you the 5th and 6th characters, in this case 86…
If you use Astonecipher’s second array which is the same I gave you awhile ago, it has a key of the number,
in this case 86 with the value of the team name. So, you need to think out what you are going to use and
what functions to use with it. If you already know the key, you do not need to format it…
Hope that helps you understand this one.
EDIT: AND, follow Astonecipher’s note on the brackets. $xyz() is a function $xyz[] is an array of data…
Numbers are integers, so unless it is something like a ssn or phone number, it doesn’t need to be in quotes. What does the array look like?
Arrays can be initialized two ways.
Actually I didn’t mix codes. If you look at what I posted at the end of page 4 its your latest code given to me that I added in for the array.
For the array I’d like to use the $filename and just have the code replace it with the university name. Which is what I was attempting in the code on page 4.
Team6.coa should change into Florida State.
Just so we are clear, would you post the current code you are working with?
[php]
<?PHP date_default_timezone_set('EST'); //NOTE: Change to EDT when Daylight Savings Time Begins $dir_path = "NCFA/exports/"; if (is_dir($dir_path)) { if ($dir = opendir($dir_path)) { $file_list = array(); while($file = readdir($dir)) { if ($file != "." and $file != "..") $file_list[] = $file . " - " . date("M d - h:i:s e", filectime($dir_path . "/" . $file)); } $team_array = array( "16" => "Syracuse", "20" => "Indiana", "21" => "Iowa", "24" => "Ohio State", "29" => "Wisconsin", ); echo "FILENAME | TIMESTAMP |
---|---|
" . $team_array(substr($filename, 5, 2)) . " | " . substr($filename,12) . " |
[/php]
The error is on line 613 which is noted.
For the table, you must link all the keys (numbers) with the team names.
Then, you need to grab the number out of the filename.
Then, use substr() to get the key from the filename.
Then, use the array of team names to get the team name for that key.
I thought we already this worked out?
For the other display that shows the numbers and team names, you just need to loop thru the array of
team names. Easy…
I do think that Astonecipher got it right. You didn’t realize that creating the array can use parens or the
brackets, but, only the brackets when you access it later… I think that is your issue now… Right? Not?
Yes, Rob, that is the problem…
$team_array(substr($filename, 5, 2)) in that line must be changed to
$team_array[substr($filename, 5, 2)]
Also, that might have been my error when I typed that originally. We have been thru a lot in this process!
If so, I am sorry…
Doing that resulted in this:
Parse error: syntax error, unexpected '", ’ (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /home/content/29/8946729/html/NCFA.php on line 614
614 is…
"82" => "Oregon",
Here is the full code:
[code]<?PHP
date_default_timezone_set('EST'); //NOTE: Change to EDT when Daylight Savings Time Begins
$dir_path = "NCFA/exports/";
if (is_dir($dir_path)) {
if ($dir = opendir($dir_path)) {
$file_list = array();
while($file = readdir($dir)) {
if ($file != “.” and $file != “…”) $file_list[] = $file . " - " . date(“M d - h:i:s e”, filectime($dir_path . “/” . $file));
}
$team_array = array(
“16” => “Syracuse”,
“20” => “Indiana”,
“21” => “Iowa”,
“24” => “Ohio State”,
“29” => “Wisconsin”,
“30” => “Colorado”,
“35” => “Nebraska”,
“36” => “Baylor”,
“45” => “Houston”,
“6” => “Florida State”,
“65” => BGSU",
“82” => “Oregon”,
“85” => “UCLA”,
“92” => “Florida”,
“98” => “Alabama”,
);
echo "<table><tr><th><b><center>FILENAME</center></b></th><th><b><center>TIMESTAMP</center></b></th></tr>";
asort($file_list);
foreach($file_list as $filename) {
echo "<tr><td>" . $team_array[substr($filename, 5, 2)] . "</td><td>" . substr($filename,12) . "</td></tr>";
}
echo "</table>";
} else {
echo "Could not open directory!";
}
} else {
echo “Not a valid directory!”;
}
?>[/code]
LOL doh!
Forgot the first parenthesis in the BGSU line…
Now the page comes back but if you look at it all of the team names are missing:
http://cfa-football.com/NCFA.php
LOL, yep, was just going to tell you that!
And, for the record, Astonecipher noted you do not need the quotes around the keys (numbers) for the
team array. (So do them or not. All should be the same…)
Okay so why are the team names not showing up now, though? LOL… Hell not even the file names show up…
Hmmm, well, try to remove some of the quotes around the numbers and see if those show up…
Nope, nothing still
LOL, and the titles for that square look weird.
Perhaps filename and timestamp should be Team and Latest Date or something??? LOL
Well, for debugging, let’s make sure it is pulling the number correctly… Try this code instead.
It will add some text to show us what is it is seeing…
[php]
echo “
This will show the number it is pulling from the filename… (Maybe it is not in the array?)
Again, modify and use this:
[php]foreach( $files as $file ) {
// remove non-digits from string (filenames)
$id = preg_replace( “/[^0-9]/”, “”, $file );
// check if the numbers in the files have a legend
// associated to it. If it does, display it.
if( array_key_exists( $id, $teams ) ) {
echo “
{$teams[ $id ]}
”;I am betting the key doesn’t match to a filename.
substr($filename, 5, 2) is off by one number. Team is 3 characters long, not 4. So, taking this as a files name “team16.coa” you are grabbing “6.” not “16”