PHP Regular Expression to get encoding
Posted on: January 12th, 2010
Tags: meta tag, preg_match, Regex, RegularExpressions
Here’s a little php function which returns the file’s character encoding from a meta tag of a webpage.
$content = file_get_contents("http://www.simra.ch");
echo getEncoding( $content );
function getEncoding( $content ) {
preg_match( '@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s+charset=([^\s"]+))?@i',$content, $matches );
return $matches[3];
}
echo getEncoding( $content );
function getEncoding( $content ) {
preg_match( '@<meta\s+http-equiv="Content-Type"\s+content="([\w/]+)(;\s+charset=([^\s"]+))?@i',$content, $matches );
return $matches[3];
}
Posted in Uncategorized | Trackback Url








No Responses to “PHP Regular Expression to get encoding”
Trackbacks/Pingbacks
Leave a reply