Javascript 如何使用Last.fm API(需要示例)PHP获取艺术家的所有图像
$returnedInfo=”“。self::API_键。“&artist=”$艺术家“&album=”$专辑“&image=”。self::$size\u map[$size]。“&format=json” $htmlContent=文件获取内容('.$artist./+images')Javascript 如何使用Last.fm API(需要示例)PHP获取艺术家的所有图像,javascript,php,Javascript,Php,$returnedInfo=”“。self::API_键。“&artist=”$艺术家“&album=”$专辑“&image=”。self::$size\u map[$size]。“&format=json” $htmlContent=文件获取内容('.$artist./+images') // We'll add all the images in this array $images = array(); // Instantiate a new object of class DOMDo
// We'll add all the images in this array
$images = array();
// Instantiate a new object of class DOMDocument
$doc = new DOMDocument();
// Load the HTML doc into the object
libxml_use_internal_errors(true);
$doc->loadHTML($htmlContent);
libxml_use_internal_errors(false);
// Get all the IMG tags in the document
$elements = $doc->getElementsByTagName('img');
// If we get at least one result
if($elements->length > 0)
{
// Loop on all of the IMG tags
foreach($elements as $element)
{
// Get the attribute SRC of the IMG tag (this is the link of the image)
$src = $element->getAttribute('src');
if (strlen($src) > 0) {
// Add the link to the array containing all the links
array_push($images, $src);
}
}