$target is a char and I am trying to find the last occurrence of that char in $line. I get -1 for every single output even if I am certain the $target does exist within $line at some index.
$fh = fopen($someFile, "r");
while (!feof($fh)) {
$test = fgets($fh);
$words = explode(",", $test);
$line = $words[0];
$target = $words[1];
$answer = strrpos($line, $target);
if ($answer !== false) {
echo $answer;
}
else echo -1;
echo "\n";
}
This code returns -1 for every single value. If I change the $line to $test in the strrpos function it can find the index every time. I checked $line to make sure it is not empty and it is in fact the first part of the string. Why doesn't this work?