0

Using php 7.1 and I have strange issue with strpos(). We have post value that needs to detect presence of # sign. Tried:

if(strpos($_POST["text"],"#")>0)
   {..} else {..}

and

if(strpos($_POST["text"],"#")!== false) 
   {..} else {..}

but it always go to else part. Also tried escaping hashtag

if(strpos($_POST["text"],"\#")>0)

Any idea what to do?

Hashtag is first value and I need to know is it present. Example value is:

$_POST["text"]='# 1010';
Ivan
  • 171
  • 2
  • 12

1 Answers1

-2
if(strpos($_POST["text"],"#")!== false)

should be used, not:

if(strpos($_POST["text"],"#")>0)

# could be the first character which is not >0.

user3783243
  • 5,368
  • 5
  • 22
  • 41