dimanche 27 mars 2016

In PHP, using file_get_contents && file_get_contents returns different values?

I was doing a mild test with the file_get_contents. The aim is to test if 2 urls do exist then see if they both have a certain string in them.

Something like:

$check_url1 = "www.example_1.com";
$check_url2 = "www.example_2.com";


if( 
$view_loaded_url1= @file_get_contents($check_url1)&&
$view_loaded_url2= @file_get_contents($check_url2)  )                                                            
{

    var_dump($view_loaded_url1); //RETURNS boolean true 

    var_dump($view_loaded_url2); //Returns the Contents of the page i.e: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Str.....etc

How do you make both return the contents of the page and not the boolean?

Because there is a second if to check if they both contain a certain string.

Something like:

if(stristr($view_loaded_url1, 'I am the String') && stristr($view_loaded_url2, 'I am the String') {

//....This part cannot go through because $view_loaded_url1 and $view_loaded_url2 are returning different datatype

}

Is this a normal behavior?.... has anyone else encountered this?

Aucun commentaire:

Enregistrer un commentaire