是的,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)。