So I'm working on a system to get the metatag from a webpage to get the info for a video embed from a link (like facebook does).
I am also getting the title of the page and the description to prefill some fields. And here is where I have a problem, the description works fine because it is a textarea so i can use .html()
but the title is an input so I can either use .attr()
or .val()
and the problem comes from special characters like (é à è ö ä ü).
Here is my code that I'm using.
This is my Jquery action script:
<script type="text/javascript" charset="utf-8">
$(function(){
$("#url").bind("change", function(){
var url = $("#url").val();
$.getJSON("/ajax/embed_video.php", { url: url }, function(json) {
$(json.embed).appendTo("#feeds");
$("#title").attr("value", json.title);
$("#description").html(json.description);
});
});
});
</script>
This is my php file for exporting the JSON data :
$url = $_GET['url'];
$result = getUrlData($url); //this get the metadata from the url
$description = $result['metaTags']['og:description']['value'];
$title = $result['metaTags']['og:title']['value'];
$img_name = basename($result['metaTags']['og:image']['value']);
copy(''.$result['metaTags']['og:image']['value'].'', "../".$path_video_temp.$img_name);
$embed = " "; //EMBED CODE
$data = array('title' => $title,'description' => $description, 'embed' => $embed, 'img' => '/'.$path_video_temp.$img_name);
header('Content-Type: application/json; Charset=UTF-8');
echo json_encode($data);
When I have a title with any accent or any special character it prints out é
etc.
I tried using html_entity_decode
and htmlspecialchars_decode
I hope someone has an idea where is the problem.
Thanks for your time and have a good day
Joris