This is my code:
function getaname($name)
{
$result = file_get_contents('https://www.something.com');
$regex = '/<div class="classname">([^<]*)<\/div>/';
if (preg_match($regex, $result, $matches)) {
return $matches[1];
} else{
return 'N/A';}
}
This code is working perfectly when preg_match
finds something in the div
but I want it to echo
or return N/A
when it finds nothing like in the dive
<div></div>