String manipulation in php is rather an easy affair, here is some simple methods to find strings within strings, extract strings, find out the length of a string and all that fun stuff kids like to do nowadays.
first things first, lets search a string
< ?php
$string = "I wish to become a doctor!";
$finder = strpos($string, "doctor");
echo $finder;
?>
that will echo out the position of the string “doctor” in the original string, I suspect it will be 19.
lets look into it a bit further,
strpos( the haystack, the needle)
The haystack being what we are searching in, and the needle is the object we are looking for. If the search turns up empty handed it will output a FALSE.
A use of this would be to check for a “@” symbol in a entered email address, if it returns false then there its not a proper email. Easy peasy
Extracting a string time,
< ?php
$string = "I'm not a balloon artist, I'm a pharmacist!";
$extract = substr($string, 0, 3);
echo $extract;
?>
that will output “I’m”,
substr( the source, start point, end point);
is the method used here but you can use it differently, for example
substr( the source, start point);
this will take the string from start point to the end of the source string.
Now lets look at finding the length of a string,
< ?php
$string = "moo";
$result = strlen($string);
echo $result;
?>
now that will output 3 due to it being 3 chars long, you can use this for example to find out the length of a password so you can validate its length is over say 6 chars long.



