У меня проблема, я пытаюсь вытащить основные метаданные из внешнего URL-адреса, и я успешно добился этого в большинстве случаев, но это вызвало несколько проблем с символами, которые являются буквами Ä ä ö выйдя как mäenjaksa7-300x200.jpg, когда я вызываю URL-адрес изображений, который на самом деле является mäenjaksa7-300x200.jpg, мой код ниже и спасибо за помощь.Вытягивание метаданных из url с php, странными символами?
function file_get_contents_curl($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data; }
$html = file_get_contents_curl($params['url']);
//parsing begins here:
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
//get and display what you need:
$urltitle = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++)
{
$meta = $metas->item($i);
if($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
if($meta->getAttribute('name') == 'keywords')
$keywords = $meta->getAttribute('content');
if($meta->getAttribute('property') == 'og:image')
$ogimage = $meta->getAttribute('content');
if($meta->getAttribute('rel') == 'image_src')
$relimage = $meta->getAttribute('content');
}
if(empty($ogimage)) {
$metaimage = $relimage;
} else {
$metaimage = $ogimage;
}
Привет спасибо за ответ, я нашел решение, похожее на вашу я добавил // Изменение кодировки в UTF-8 из ISO-8859-1 $ html = iconv ('UTF-8', 'ISO-8859-1 // TRANSLIT', $ html); под $ html = file_get_contents_curl ($ url); теперь мне просто нужно выяснить, почему я не могу назвать теги rel = "image_src" – David