How to validate a 404 on a page with an if

0

I am using the following code

for($pagina=50;$pagina<60;$pagina++){

$data = file_get_contents("http://www.pagina.net/?p=".$pagina);

 if ( preg_match('|<h2 class="titulo">(.*?)</h2>|is' , $data , $cap ) )
{

    echo '<br><b>'.$cap[1] .'</b>';
}

}
?>

In case a page for example: www.pagina.net/?php="200 "gives me an error 404 not found as I would to identify it in php and make a condition if?

Something like this:

if( $data = 404 not found)
{ echo "no rastrear" }
else { seguir rastreando }

I'm grabbing your help

    
asked by Camaliet 03.12.2018 в 13:17
source

1 answer

0

In wordpress ...

<?php
    if ( is_404() ) {
        echo "no rastrear"
    } else {
        // Seguir Rastreando
    }
?>
    
answered by 04.12.2018 в 23:19