php - converting special characters after reading a site's meta tags -
php - converting special characters after reading a site's meta tags -
i'm pulling facebook meta tags external site code, works:
$site = file_get_contents($link); $html = new domdocument(); @$html->loadhtml($site); $meta_title = null; foreach($html->getelementsbytagname('meta') $meta) { if($meta->getattribute('property')=='og:title'){ $meta_title = $meta->getattribute('content'); } } echo 'og:title: '.$meta_title;
my problem if og:title contains apostrophe, example, outputs bunch of funky characters. example:
that̢۪s spot
instead of:
that's spot
how create output correctly?
check 3rd part website collation, on utf-8 or latin.
then should convert website collation. using? utf8 or latin?
if using utf8 , 3rd part latin, should utilize
utf8_encode($actualvar)
if using latin , 3rd part utf8, should utilize
utf8_decode($actualvar)
i suppose there 2 different collations ruling it. if 2 utf8 convert php header utf8 too:
header('content-type: text/html; charset=utf-8');
if trying utilize latin (iso-8859-1) utilize
header('content-type: text/html; charset=iso-8859-1');
by wall should work way.
php
Comments
Post a Comment