View Full Version : strpos() troubles

11-28-2007, 04:21 AM
Minor problem with strpos()... If $value is present at the very start of my string $row->mfg_types, the strpos() fails to match. I worked around this by adding the underscore as the first character but what am I doing incorrectly? I understand that it is returning a zero (string matched starting at character 0) which is also boolean false.

$checkboxes = explode('|', $MFG_TYPES);
echo "\n<tr><td>Mfg. Types:</td><td>";
foreach ($checkboxes as $value) {
echo "<input type=\"checkbox\" value=\"$value\" name=\"mfg[]\"";
if (!strpos('_'.$row->mfg_types, $value) === false) {
// the '_' was added at front because the function wouldn't
// pickup if the $value started as the first character of the string
echo " checked=\"on\"";
echo ">$value<br />\n";
echo "</td></tr>\n";

11-28-2007, 04:39 AM
You are using !strpos(....) === false when you should be using strpos(...) !== false. When strpos() returns 0 as a "found" value, you are effectively saying !0 or !false. Obviously that means !false = true. The final comparison ends up being !false === false or true === false, which is always false. Remove the ! in fornt of strpos(...) and change === to !==

That should help.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum