Quote:
Originally Posted by sortie
Then you do a boolean test on the result for the "echo", correct?
|
Not quite. For PHP, anything that isn't 0 is considered to be legitimate. I used a ternary operator because I love 'em.
Another way of writing it would be if ($test != FALSE) { echo "Found." } else { echo "Not found." }
See the link on strpos above; my shorthand was a little difficult to read if you're not familiar with the nuances of PHP, but it's valid.
Code:
<?php
$data="hello";
$testfor="h";
$test=strpos($data, $testfor);
echo ($test != FALSE) ? "'$testfor' found in '$data'.\n" : "'$testfor' not found in '$data'.\n";
?>
It's precisely the same, only with more text in it. As noted, 0 has the same value as FALSE, so unless you explicitly test for it, you can have nasty results.