Monday, May 21, 2012

Compare a string from $_GET with a string from an array

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.

No comments:

Post a Comment