encoding - simpleXML with special chars in XML-Url -
i have little problem code. trying pull song id's spotify. works fine me, not special characters in url (like ü,ö,ä).
i warning (first line echoed url):
http://ws.spotify.com/search/1/track?q=sportfreunde+stiller+and+track:frühling warning: simplexmlelement::__tostring() [simplexmlelement.--tostring]: node no longer exists in /applications/ampps/www/spotify.php on line 28
this code:
function getid($artist,$title){ $url = utf8_decode("http://ws.spotify.com/search/1/track?q=".$artist."+and+track:".$title); echo $url; $xml = simplexml_load_file($url); $id= $xml->track->attributes(); return($id); } echo getid("sportfreunde+stiller","frühling");
how solve this? tried utf_encode(), didn't work out.
thank you!
this has nothing utf-8 encoding, , not badly named utf8_decode
/utf8_encode
functions, should named utf8_to_iso8859_1
/iso8859_1_to_utf8
, , right answer encoding problem.
urls can, strictly speaking, contain restricted set of characters - basic letters, numbers, , few pieces of punctuation. else must escaped using sequences %3f
.
to escape strings in url correctly, can use php function urlencode()
, e.g.
$url = "http://ws.spotify.com/search/1/track?q=" . urlencode($artist) . "+and+track:" . urlencode($title);
Comments
Post a Comment