$str = "12345";
if (is_string($str) && is_numeric($str)) {
echo "The string is a numeric string";
} else {
echo "The string is not a numeric string";
}
$str = "Hello World";
$char = "W";
if (is_string($str) && strpos($str, $char) !== false) {
echo "The string contains the character '$char'";
} else {
echo "The string does not contain the character '$char'";
}
$str = "Hello World";
$subStr = "Hello";
if (is_string($str) && substr($str, 0, strlen($subStr)) === $subStr) {
echo "The string starts with the substring '$subStr'";
} else {
echo "The string does not start with the substring '$subStr'";
}
$str = "Hello World";
$subStr = "World";
if (is_string($str) && substr($str, -strlen($subStr)) === $subStr) {
echo "The string ends with the substring '$subStr'";
} else {
echo "The string does not end with the substring '$subStr'";
}
$str = "hello world";
if (is_string($str) && ctype_lower($str)) {
echo "The string is all lowercase";
} else if (is_string($str) && ctype_upper($str)) {
echo "The string is all uppercase";
} else {
echo "The string is mixed case";
}
這些是php is_string函數的一些高級應用,可以用來更詳細地判斷字符串的特性和內容。