As for reading, try something like this:
$contents = ereg_replace(">","\n",$contents);
$lines = split("\n",$contents);
foreach ($lines as $line) {
$line = trim($line);
$spaced = split(" ",$line,2);
$tag = $spaced[0];
$params = split(" ",$spaced[1]);
switch ($tag) {
case "<meta":
for ($i=0;$i<=count($params);$i++) {
$param_name = split("=",$params[$i]);
$value = ereg_replace("#|\"|>","",$param_name[1]);
switch ($param_name[0]) {
case "content":
//do what if it's reading the content part
break;
case "description":
//do what if it's reading the description
break;
break;
}
}
}
}
This is just a little alteration of an HTML parser I wrote. You might be able to optimize that to run better with only the meta tag. Feel free to change it so you can use only whatever you need.
When rewriting, you'll have to use replacements. Try looking up ereg_replace, str_replace, preg_replace. You can use the values gathered from the code I gave to rewrite it, as well.