PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The (Michigan web site)

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY The strpos() function takes two arguments: a string that you want to search, and a character or substring that you want to find in it. If it finds the substring that you re looking for, strpos() returns the position of the first character. Since the position of characters in strings is always counted from 0, it s essential to use the identical operator (three equal signs) to make sure that the result of strpos($key, ‘Submit’) is genuinely 0, and not a false negative. To see what I mean, alter the following line: if (strpos($key, ‘Submit’) === 0) { // CORRECT Change it to this: if (strpos($key, ‘Submit’) == 0) { // WRONG If you test the sequence again, you ll see that no results are displayed. This is because strpos() returns false if it can t find the substring; and PHP interprets 0 as false. What you re looking for is not false, but Submit at the beginning of the string in other words, position 0. The identical operator guarantees that the items you re comparing not only have the same value, but are also of the same data type. Don t worry if that last part went over your head. Just remember that when using strpos() to find a character or substring at the start of a string, use the identical oper- ator (===) and not the equality operator (==). The foreach loop on the final page of this example displays the contents of the $_SESSION array onscreen. In a real application, you would use the session variables to build the content of an email message or to prepare a SQL query to insert the information in a database. Coming up . . . If you started this book with little or no knowledge of PHP, you re no longer in the beginners league, but are leveraging the power PHP in a lot of useful ways. Hopefully, by now, you ll have begun to appreciate that the same or similar techniques crop up again and again. Instead of just copying code, you should start to recognize techniques that you can adapt to your needs and experiment on your own. The rest of this book continues to build on your knowledge, but brings a new factor into play: the MySQL relational database, which will take your PHP skills to a higher level. The next chapter shows you how to install MySQL and get it ready for use. Then you ll learn the basics of working with MySQL and a PHP-driven graphical interface called phpMyAdmin before bringing PHP back into the picture.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply