开发者

String with £ symbol returns question black diamond mark PHP

开发者 https://www.devze.com 2023-02-26 19:56 出处:网络
I am g开发者_如何学运维rabbing meta descriptions from remote urls and when a url contains \"£\" it returns as a black diamond with a question mark in firefox. When I apply utf8_encode on the string,

I am g开发者_如何学运维rabbing meta descriptions from remote urls and when a url contains "£" it returns as a black diamond with a question mark in firefox. When I apply utf8_encode on the string, it returns "£" as it should, however then other UTF characters will not display correctly. What can I do?


Did you set the content type meta tag on the page?

http://www.w3schools.com/tags/att_meta_http_equiv.asp

Edit:

To solve what you put in your comment, I might do something like this (super quick and dirty):

<?php

$ch = curl_init('http://www.dailymail.co.uk/health/article-1374575/Under-18s-sunbed-ban-cut-skin-cancer-toll.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

preg_match('/(<meta[^\n]+)(name=\"description\"[^\n])(content=\")([^\n]+)(\")/', $data, $m);
echo urlencode($m[4]);

?>

Having said that, the correct way of doing this would be to parse the HTML returned by the curl_exec, find the appropriate node (with name="description") and return the urlencoded value of the content attribute

0

精彩评论

暂无评论...
验证码 换一张
取 消