src/lastfmapi/Api/ArtistApi.php
public function search($methodVars)
    {
        // Check for required variables
        if (!empty($methodVars['artist'])) {
            $vars = array(
                'method' => 'artist.search',
                'api_key' => $this->auth->apiKey
            );
            $vars = array_merge($vars, $methodVars);

            if ($call = $this->apiGetCall($vars)) {
                $callNamespaces = $call->getDocNamespaces(true);
                // fix missing namespace (sic)
                if (!isset($callNamespaces['opensearch'])) {
                    $call->results->addAttribute('xmlns:xmlns:opensearch', 'http://a9.com/-/spec/opensearch/1.1/');
                    $call = new SimpleXMLElement($call->asXML());
                }
                $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/');
                if ($opensearch->totalResults > 0) {
                    $searchResults['totalResults'] = (string) $opensearch->totalResults;
                    $searchResults['startIndex'] = (string) $opensearch->startIndex;
                    $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage;
                    $i = 0;
                    foreach ($call->results->artistmatches->artist as $artist) {
                        $searchResults['results'][$i]['name'] = (string) $artist->name;
                        $searchResults['results'][$i]['mbid'] = (string) $artist->mbid;
                        $searchResults['results'][$i]['url'] = (string) $artist->url;
                        $searchResults['results'][$i]['streamable'] = (string) $artist->streamable;
                        $searchResults['results'][$i]['image']['small'] = (string) $artist->image[0];
                        $searchResults['results'][$i]['image']['medium'] = (string) $artist->image[1];
                        $searchResults['results'][$i]['image']['large'] = (string) $artist->image[2];
                        $searchResults['results'][$i]['image']['extralarge'] = (string) $artist->image[3];
                        $searchResults['results'][$i]['image']['mega'] = (string) $artist->image[4];
                        $i++;
                    }

                    return $searchResults;
                } else {
                    throw new NoResultsException('No results');
                }
            } else {
                return false;
            }
        } else {
            throw new InvalidArgumentException('You must include artist variable in the call for this method');
        }
    }
public function search($methodVars)
    {
        // Check for required variables
        if (!empty($methodVars['artist'])) {
            $vars = array(
                'method' => 'artist.search',
                'api_key' => $this->auth->apiKey
            );
            $vars = array_merge($vars, $methodVars);

            if ($call = $this->apiGetCall($vars)) {
                $callNamespaces = $call->getDocNamespaces(true);
                // fix missing namespace (sic)
                if (!isset($callNamespaces['opensearch'])) {
                    $call->results->addAttribute('xmlns:xmlns:opensearch', 'http://a9.com/-/spec/opensearch/1.1/');
                    $call = new SimpleXMLElement($call->asXML());
                }
                $opensearch = $call->results->children('http://a9.com/-/spec/opensearch/1.1/');
                if ($opensearch->totalResults > 0) {
                    $searchResults['totalResults'] = (string) $opensearch->totalResults;
                    $searchResults['startIndex'] = (string) $opensearch->startIndex;
                    $searchResults['itemsPerPage'] = (string) $opensearch->itemsPerPage;
                    $i = 0;
                    foreach ($call->results->artistmatches->artist as $artist) {
                        $searchResults['results'][$i]['name'] = (string) $artist->name;
                        $searchResults['results'][$i]['mbid'] = (string) $artist->mbid;
                        $searchResults['results'][$i]['url'] = (string) $artist->url;
                        $searchResults['results'][$i]['streamable'] = (string) $artist->streamable;
                        $searchResults['results'][$i]['image']['small'] = (string) $artist->image[0];
                        $searchResults['results'][$i]['image']['medium'] = (string) $artist->image[1];
                        $searchResults['results'][$i]['image']['large'] = (string) $artist->image[2];
                        $searchResults['results'][$i]['image']['extralarge'] = (string) $artist->image[3];
                        $searchResults['results'][$i]['image']['mega'] = (string) $artist->image[4];
                        $i++;
                    }

                    return $searchResults;
                } else {
                    throw new NoResultsException('No results');
                }
            } else {
                return false;
            }
        } else {
            throw new InvalidArgumentException('You must include artist variable in the call for this method');
        }
    }
public function search ( $ methodVars ) { // Check for required variables if ( ! empty ( $ methodVars [ 'artist' ] ) ) { $ vars = array ( 'method' => 'artist.search' , 'api_key' => $ this -> auth -> apiKey ) ; $ vars = array_merge ( $ vars , $ methodVars ) ; if ( $ call = $ this -> apiGetCall ( $ vars ) ) { $ callNamespaces = $ call -> getDocNamespaces ( true ) ; // fix missing namespace (sic) if ( ! isset ( $ callNamespaces [ 'opensearch' ] ) ) { $ call -> results -> addAttribute ( 'xmlns:xmlns:opensearch' , 'http://a9.com/-/spec/opensearch/1.1/' ) ; $ call = new SimpleXMLElement ( $ call -> asXML ( ) ) ; } $ opensearch = $ call -> results -> children ( 'http://a9.com/-/spec/opensearch/1.1/' ) ; if ( $ opensearch -> totalResults > 0 ) { $ searchResults [ 'totalResults' ] = ( string ) $ opensearch -> totalResults ; $ searchResults [ 'startIndex' ] = ( string ) $ opensearch -> startIndex ; $ searchResults [ 'itemsPerPage' ] = ( string ) $ opensearch -> itemsPerPage ; $ i = 0 ; foreach ( $ call -> results -> artistmatches -> artist as $ artist ) { $ searchResults [ 'results' ] [ $ i ] [ 'name' ] = ( string ) $ artist -> name ; $ searchResults [ 'results' ] [ $ i ] [ 'mbid' ] = ( string ) $ artist -> mbid ; $ searchResults [ 'results' ] [ $ i ] [ 'url' ] = ( string ) $ artist -> url ; $ searchResults [ 'results' ] [ $ i ] [ 'streamable' ] = ( string ) $ artist -> streamable ; $ searchResults [ 'results' ] [ $ i ] [ 'image' ] [ 'small' ] = ( string ) $ artist -> image [ 0 ] ; $ searchResults [ 'results' ] [ $ i ] [ 'image' ] [ 'medium' ] = ( string ) $ artist -> image [ 1 ] ; $ searchResults [ 'results' ] [ $ i ] [ 'image' ] [ 'large' ] = ( string ) $ artist -> image [ 2 ] ; $ searchResults [ 'results' ] [ $ i ] [ 'image' ] [ 'extralarge' ] = ( string ) $ artist -> image [ 3 ] ; $ searchResults [ 'results' ] [ $ i ] [ 'image' ] [ 'mega' ] = ( string ) $ artist -> image [ 4 ] ; $ i ++ ; } return $ searchResults ; } else { throw new NoResultsException ( 'No results' ) ; } } else { return false ; } } else { throw new InvalidArgumentException ( 'You must include artist variable in the call for this method' ) ; } }
Search for an artist by name. Returns artist matches sorted by relevance
@param array $methodVars An array with the following required value: <i>artist</i> and optional values: <i>limite</i>, <i>page</i>
@return array
Search for an artist by name . Returns artist matches sorted by relevance