2

I'm using a php lib to retrieve the opengraph tags from a website https://github.com/scottmac/opengraph/blob/master/OpenGraph.php

<?php
header("Content-Type: text/html; charset=utf-8");
$url = 'http://www.youtube.com/watch?v=ogHIUNfu2vY';
require_once $_SERVER['DOCUMENT_ROOT'] . '/php/libs/opengraph/OpenGraph.php';

$graphObj = OpenGraph::fetch($url);

echo '<pre>';
print_r($graphObj);
echo '</pre>';

This title is incorrectly retrieved as

[title] => Hüsker Dü - I'll Never Forget You

It should be

[title] => Hüsker Dü - I'll Never Forget You

How can I retrieve the open graph tags in utf-8?

Martin Brisiak
  • 3,872
  • 12
  • 37
  • 51
user784637
  • 15,392
  • 32
  • 93
  • 156
  • i'll bet this has to do with how the actual physical file is encoded. check [this post](http://stackoverflow.com/a/6146066/977083) to determine and change file encoding – code_monk Nov 02 '14 at 21:49
  • ...and in a pinch, these quick and dirty helper functions have been known to save the day: [function.utf8-encode](http://ca3.php.net/manual/en/function.utf8-encode.php), [function.utf8-decode](http://ca3.php.net/manual/en/function.utf8-decode.php) – code_monk Nov 02 '14 at 21:51
  • I don't know what the original encoding is, but I assume it is utf-8. Also - the first helper function only converts from ISO-8859-1 chars to utf-8. I don't think the original encoding is in ISO-8859-1. – user784637 Nov 02 '14 at 21:55

1 Answers1

-2
$graph = OpenGraph::fetch($url);
$body = current($graph);
$description = utf8_decode($body['description']);
jsh
  • 1