I am wanting to do a simple extraction of the
three key header elements from a web page namely these:
<title>This the Title</title>
<meta name="keywords" content="PHP, javascript, other keywords" />
<meta name="description" content="This is the description." />
Is the preg_match() function the best way to find them and put them
into variables ?
If they are not found of the web page I would like to fill the relevant variable
ith "Not found".
I have wriiten this code but I am not sure if it is the best approach
or if the logic is correct.
$title = preg_match("/<title>(.*?)</title>/",$text,$matches);
if ($title === false) {
$title = "None found";
}
$descrip = preg_match("/<meta name=\"description\" content=\"(.*?)\"/",$text,$matches);
if ($descrip === false) {
$descrip = "None found";
}
$keys = preg_match("/<meta name=\"keywords\" content=\"(.*?)\"/",$text,$matches);
if ($keys === false) {
$keys = "None found";
}
Any suggestions, corrections most welcome.