1

I'm trying to find if there's a period in a string with strpos, but for some reason it prints out "There's no period." every time I run the code. I'm not sure what I did wrong.

$text = "Hello.";

if (strpos($text, "." !== false)) {
echo "There's a period.";
}
else {
echo "There's no period.";
}

Expected result

There's a period.

Actual result

There's no period.
jessica
  • 1,667
  • 1
  • 17
  • 35

1 Answers1

3

Your parenthesis are not matching correctly.

With the way you have it right now, you are passing the result of "." !== false as the second argument to strpos.

Change

if (strpos($text, "." !== false)) {

to

if (strpos($text, ".") !== false) {
Zsw
  • 3,920
  • 4
  • 29
  • 43