0

I have this code which is to check if google exist in the external array file, it gives me the blank result but when i transferred the array into the same file or inline the list, it works. I'm using the external array file for global use.

$approveurl = file('../webfilters.php');
if(in_array('http://google.com', $approveurl)){ echo "Success";} 
7
  • what is the external array file ? Commented Dec 11, 2019 at 4:37
  • The external array file looks like this vergleich-webhosting.info alltemplate.org executivestudio.net Commented Dec 11, 2019 at 4:38
  • you want to check the html code of this sites to see if there is the string http://google.com ? Commented Dec 11, 2019 at 4:41
  • Yes, the file() code returns the external file into array when i use the var_dump($approveurl) it will show the list into array form. Commented Dec 11, 2019 at 4:42
  • At a minimum you need to use the FILE_IGNORE_NEW_LINES flag, otherwise all the strings in the array will end with newline, so they won't match. Commented Dec 11, 2019 at 4:45

1 Answer 1

1

There's no need to turn the file into an array. Read it into a string and then use strstr().

$data = file_get_contents("../webfilters.php");
if (strstr($data, "http://google.com")) {
    echo "Success";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.