我试图找到带有strpos的字符串中的句点,但由于某种原因,它打印出来"没有句号。"每次我运行代码。我不确定我做错了什么。
$text = "Hello.";
if (strpos($text, "." !== false)) {
echo "There's a period.";
}
else {
echo "There's no period.";
}
预期结果
There's a period.
实际结果
There's no period.
答案 0 :(得分:3)
您的括号未正确匹配。
按照现在的方式,您将"." !== false
的结果作为第二个参数传递给strpos
。
更改
if (strpos($text, "." !== false)) {
到
if (strpos($text, ".") !== false) {