Using Strings In PHP strpos

Using the strpos function in PHP

Error checking is fundamental with programming. One of the easiest things to check to see if something was entered correctly is if a character or a string is contained within a string that was submitted. That is where sthe function strpos comes in. strpos returns an integer value of the position of what you are looking for and false if it doesn’t find it.

A good example is checking to see if a user submitted their email address correctly. Thus we have:

1. $email = “something@someplace.com”; 2. If (substr($email, “@”)) {
3. print “Email address is good”;
4. } else print “Email address is bad”;
This is a fairly straight forward example that just checks to see if the @ symbol is actually in the string provided.

Other functions for manipulating strings: