Skip to content

Instantly share code, notes, and snippets.

@legnoh
Created November 17, 2012 01:29
Show Gist options
  • Save legnoh/4092477 to your computer and use it in GitHub Desktop.
Save legnoh/4092477 to your computer and use it in GitHub Desktop.
Recognition of Character Code
$tags = get_meta_tags($res->url);
$headers = get_headers($res->url,1);
$ctype = $headers['Content-Type'];
if(preg_match('/utf-8|euc-jp|shift_jis|iso-2022-jp/iu',$ctype,$cset)){
switch($cset[0]){
case 'euc-jp':
case 'EUC-JP':
$tag_key = mb_convert_encoding( $tags['keywords'], 'UTF-8' , 'eucJP-win');
$tag_desc = mb_convert_encoding( $tags['description'],'UTF-8' , 'eucJP-win');
break;
case 'shift_jis':
case 'Shift_JIS':
case 'SHIFT_JIS':
$tag_key = mb_convert_encoding( $tags['keywords'], 'UTF-8' , 'SJIS-win');
$tag_desc = mb_convert_encoding( $tags['description'],'UTF-8' , 'SJIS-win');
break;
case 'iso-2022-jp':
$tag_key = mb_convert_encoding( $tags['keywords'], 'UTF-8' , 'ISO-2022-JP');
$tag_desc = mb_convert_encoding( $tags['description'],'UTF-8' , 'ISO-2022-JP');
break;
case 'utf-8':
default:
$tag_key = $tags['keywords']; // keyword
$tag_desc = $tags['description']; // description
break;
}
}else{
$tag_key = $tags['keywords']; // keyword
$tag_desc = $tags['description']; // description
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment