Check if value exists in external file array php

2251 views php

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('', $approveurl)){ echo "Success";} 

answered question

what is the external array file ?

The external array file looks like this

you want to check the html code of this sites to see if there is the string ?

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.

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.

as far as I know in_array checks if you have one complete element in the "haysack" that is equal to the "needle" . for such things I would use file_get_contents and then you use strpos($needle, $haysack)

Okay, Thank you for this help, i added the code and it works!!

2 Answers


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, "")) {
    echo "Success";

posted this

Use can try like this -

$file   = file('../webfilters.php');

foreach ($file as $key => $value) {

  $temp = explode(',', $value);

  if ($temp[0] == ''){
    echo ' is found';
    exit;} }

posted this

Have an answer?


Please login first before posting an answer.