This has been frustrating me, because I'm pretty new to PHP and am sure I'm missing something very basic about the nature of the language. But why oh why won't this work?
$tag = $_GET['id'];
$openfile = fopen($files[$i], "r");
$tagsraw = fgets($openfile);
$tag_array = explode(",",$tagsraw);
foreach ($tag_array as $a) {
if ($a == $tag) {
echo $a." matches ".$tag;
}
}
EDIT: The file-opening works fine, by the way; print_r()
shows that $tag_array
populates how it's meant to.
EDIT: Here's the printout from print_r()
. There are five files, and each has its tags in the first line.
Array
(
[0] => webdesign
)
Array
(
[0] => personal
)
Array
(
[0] => recipes
[1] => vegan
)
Array
(
[0] => personal
)
Array
(
[0] => personal
)
$files
? – aziz punjani May 21 '12 at 14:39id
get parameter? Also, are you sure there aren't any trailing or leading spaces in any of those tags? – Eric Petroelje May 21 '12 at 14:41$files
is an array containing paths to .txt files, andfopen()
andfget()
both work how they're meant to. I can post the rest of the code if you need, I was just hoping that I'd made some glaringly obvious gaff in these few lines. – lowercasename May 21 '12 at 14:41var_dump
to see what's in each of the variables Tryvar_dump($_GET); var_dump($tag_array);
. Add anelse
onto your if-statement to see when it fails. Try changing it toif (trim($a) == trim($tag))
. – Travesty3 May 21 '12 at 14:46