|
Fedora™ Unleashed, 2008 editionIf you recall, any nonzero number equates to true in PHP, which means that 0 equates to false. With that in mind, what is the string index of the first The in the phrase? Because PHP's strings are zero-based and we no longer have the spaces on either side of the string, the The is at position 0, which the conditional statement evaluates to false — hence, the problem. The solution here is to check for identicality. You know that 0 and false are equal, but they are not identical because 0 is an integer, whereas false is a Boolean. So, we need to rewrite the conditional statement to see whether the return value from strpos() is identical to false. If it is, the substring is not found: <?php В $ourstring = "The Quick Brown Box Jumped Over The Lazy Dog"; В if (strpos($ourstring, "The") !== false) { В В echo "Found 'The'!\n"; В } else { В echo "'The' not found!\n"; В } ?> Arrays Working with arrays is no easy task, but PHP makes it easier by providing a selection of functions that can sort, shuffle, intersect, and filter them ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|