是的,PHP 的 stripos() 函數可以查找字符串中的空格。stripos() 是 strpos() 的字符串搜索的變體,它不區分大小寫。該函數在目標字符串中搜索給定字符串的首次出現,并返回其位置索引。如果未找到,則返回 false。
這是一個使用 stripos() 查找空格的基本示例:
$string = "Hello World!";
$search = " "; // 空格字符
$position = stripos($string, $search);
if ($position !== false) {
echo "The position of the first space is: " . $position; // 輸出:The position of the first space is: 5
} else {
echo "No space found.";
}
在這個例子中,stripos() 函數會在 $string 中查找空格,并返回其位置索引(5)。