Im building an application that interacts with the Twitter API.
So far my code handles the responses correctly and I am happy with the way i am interacting with search API. I am however stuck when it comes to the actual content from the Twitter API responses.
Right now, i search for tweets with specific hastags using the atom feed, i.e.
$url = 'http://search.twitter.com/search.atom?q='.urlencode($hash_tag) ;
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);
$twelement = new SimpleXMLElement($xml);
echo "<pre>";
foreach ($twelement->entry as $entry) {
echo($entry->author->name);
echo '<br />';
echo mb_detect_encoding($entry->author->name);
echo '<br />';
I have been trying different php functions to decode/convert to the correct character encoding, but no matter what i do, i always end up with the wrong output.
My output from this code is : (crossed out for privacy)
xxxxxx (xxxxx xxxxxxx)
ASCII
xxxx_xxxxx (Chinny ♥_♥)
UTF-8
kunlemyk ((˘̯˘ ) hardekhunley™)
UTF-8
xxxx_xxxxx (♥ify okwuosa♥)
UTF-8
xxx_xxxx (Call me DRO)
ASCII
Why are some ASCII and some UTF-8? how can i ensure they are consistent. can i convert them to ascii? im pretty lost here. I have been stuck on this for ages and would really appreciate some help here.
Regards,
Andrew