I have the following regular expression that I need tweaked, but everything I do seems to be wrong. This expression extracts out all meta tags from text. i know there is a function for this in php, but that function only works if the tags are coming from a webpage.
function get_meta_tags($input){
while($input = strstr($input,"<meta")) {
$pos_close = strpos($input,">") + 1;
$array[] = substr( $input , 0 , $pos_close);
$input=substr( $input , $pos_close);
}
for($i=0; $i<count($array); $i++) {
eregi('<meta +(name|httpd-equiv|http-equiv) *= *"?([^">]*)"? +content *= *"?([^">]*)[^>]*>',$array[$i],$r);
$meta[strtolower($r[2])] = $r[3];
}
return $meta;
}
The above code works great if the meta tag is in the format of:
<meta name="keywords" content="whatever">
but it does not work if the format is:
<meta name=keywords content=whatever>
or if the format is;
<meta content="whatever" name="keywords">
Any and all help on this regular express would be greatly appreciated.