PHP的strchr函數用于在字符串中查找第一次出現某個字符的位置
例如,如果你想在字符串"Hello World"中查找空格并忽略它,你可以這樣做:
$str = "Hello World";
$char = " ";
$position = strpos($str, $char);
if ($position !== false) {
echo "The position of the first space is: " . $position;
} else {
echo "No space found in the string.";
}
在這個例子中,strpos函數會返回空格在字符串中的位置(即1),而不是使用strchr函數。