Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

Check out soundex, metaphone, and similar_text for alternative ways of
comparing strings.


<?


$first = "abc";
$second = "xyz";


if(strcmp($first, $second) == 0)
{
print("strings are equal");
}
else
{
print("strings are not equal");
}
?>


integer strcspn(string text, string set)


The strcspn function returns the position of the first character in the text argument
that is part of the set argument. Compare this function to strspn.


<?


$text = "red cabbage";
$set = "abc";
$position = strcspn($text, $set);


// prints 'red '
print(substr($text, 0, $position));
?>


string stristr(string text, string substring)


The stristr function is a case-insensitive version of strstr, below. A portion of the
text argument is returned starting from the first occurrence of the substring
argument to the end.


<?


$text = "Although he had help, Leon is the author
of

Free download pdf