2

I am trying to find a instance of a string inside another using strpos() but I am having problems.

      if(strpos($line, $_GET['search']) !== FALSE){ //does not work

$line is a single line of a text file read in by fgets() and $_GET['search'] is text passed in via the url. This code never gets a match. However same line with $_GET['search'] replaced with straight text works fine.

      if(strpos($line, "test") !== FALSE){ //got a match, works

I have tried casting the $_GET variable with strval, and nothing seems to work. Any help would be appreciated. Thanks in advance

  • 1
    There's probably something in `$_GET['search']` that you're not expecting, like extra whitespace. Maybe use `trim()` to clean it up. Use `var_dump($_GET['search']);` to see what's exactly in it. – Barmar Nov 10 '20 at 00:47
  • Thank you. I didn't realize that I was getting the $_GET string wrapped in quotes. That would account for it. Thank you. – general_chaos40 Nov 10 '20 at 01:21
  • Sounds like a problem with the code that's generating the URL, it's adding unnecessary quotes. – Barmar Nov 10 '20 at 01:22
  • first you should test your value from get using var_dump – Jerson Nov 10 '20 at 02:12

0 Answers0