Here's a piece of code that should work for the problem that Rusty was talking about. (Basically, only allow 1 "?" in a string.)
** Tom ** 
---------------------------------
$string_to_test = "This is a test string? I don't know, is it?";
$once_only = "?";
$oo_pos = strpos($string_to_test, $once_only, 0);
if ($oo_pos === false)
{
// not found case
echo "No question found ";
}
else
{
$oo_sec = strpos($string_to_test, $once_only, $oo_pos+1);
if ($oo_sec === false)
{
// Just one found
echo "Success, found a question ";
}
else
{
// found more than one
echo "Opps! Found more than one question ";
}
}
?> |