Поиск текста песни
- <?php
- ///Autor HoldFast
- ///2013 year
- error_reporting(0);
- mb_internal_encoding("UTF-8");
- class LyricsWikia
- {
- function searchSong($artist, $title)
- {
- $artist = mb_convert_case($artist, MB_CASE_TITLE, "UTF-8");
- $title = mb_convert_case($title, MB_CASE_TITLE, "UTF-8");
- $replace = array(
- "ё" => "е",
- "Ё" => "Е"
- );
- $artist = strtr($artist, $replace);
- $title = strtr($title, $replace);
- $xml = file_get_contents("http://lyrics.wikia.com/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" . rawurlencode($artist) . ":" . rawurlencode($title));
- if (!empty($xml)) {
- $xml = @new SimpleXMLElement($xml);
- if (preg_match("/#REDIRECT \[\[(.*):(.*)\]\]/", $xml->query->pages->page->revisions->rev, $m)) {
- $xml = file_get_contents("http://lyrics.wikia.com/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" . rawurlencode($m[1]) . ":" . rawurlencode($m[2]));
- $xml = @new SimpleXMLElement($xml);
- }
- if (empty($xml->query->pages->page->revisions->rev)) {
- $xml = file_get_contents("http://lyrics.wikia.com/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" . rawurlencode($artist));
- $xml = @new SimpleXMLElement($xml);
- if (preg_match("/#REDIRECT \[\[(.*)\]\]/", $xml->query->pages->page->revisions->rev, $m)) {
- $xml = file_get_contents("http://lyrics.wikia.com/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=" . rawurlencode($m[1]) . ":" . rawurlencode($title));
- $xml = @new SimpleXMLElement($xml);
- }
- }
- $str = explode('<lyrics>', $xml->query->pages->page->revisions->rev);
- $str = explode('</lyrics>', $str[1]);
- $text = trim($str[0]);
- if($text == '{{Instrumental}}') $text = 'Instrumental';
- }
- return $text;
- }
- }
- ?>
Класс для поиска текстов. Все извращения, которые вы увидите в коде - это обязательная фича для поиска по русским текстам
Пример использования:
Пример использования:
- <?
- require "class.lyric.php";
- $text = new LyricsWikia();
- echo str_replace("\n","<br>",$text->searchSong('Arch Enemy', 'Nemesis'));
- ?>