通过与php的相关性来命令json结果(similar_text)

时间:2014-06-18 09:26:36

标签: php json

我正在使用soundcloud上的音乐搜索系统,我设法用 similar_text php函数显示每个结果的相关性。

现在我需要在订单中按照" rating"

排序结果

使用 similar_text 函数生成评级值,与搜索查询

进行比较

这是我的字符串(json响应)。

[{
    "title": "Enrique Iglesias - Bailando Ft. Sean Paul, Descemer, Gente De Zona",
    "server": "soundcloud",
    "id": "OuHvWaTpwloS",
    "rating": 48.3516483516,
    "download": "request",
    "size": "9.24 MB",
    "duration": "04:02"
}, {
    "title": "Enrique Iglesias-  Bailando  (2014)",
    "server": "soundcloud",
    "id": "0kT5RsEIiOht",
    "rating": 73.3333333333,
    "download": "request",
    "size": "3.74 MB",
    "duration": "04:05"
}, {
    "title": "Enrique Iglesias - Bailando Ft. Descemer Bueno, Gente De Zona Remix",
    "server": "soundcloud",
    "id": "jWXem932vahQ",
    "rating": 47.8260869565,
    "download": "request",
    "size": "4.05 MB",
    "duration": "04:25"
}, {
    "title": "Enrique Iglesias \"i'm A Freak\" F. Pitbull",
    "server": "soundcloud",
    "id": "PdlkwSBrgZ7L",
    "rating": 51.5151515152,
    "download": "request",
    "size": "36.79 MB",
    "duration": "03:38"
}, {
    "title": "Enrique Iglesias - \"bailando\"",
    "server": "soundcloud",
    "id": "ziPjLd4EI2nt",
    "rating": 85.1851851852,
    "download": "request",
    "size": "37.34 MB",
    "duration": "03:42"
}, {
    "title": "Enrique Iglesias - Finally Found You (r3hab & Zroq Remix)",
    "server": "soundcloud",
    "id": "mMmaa8wo1dDW",
    "rating": 48.7804878049,
    "download": "request",
    "size": "38.80 MB",
    "duration": "03:50"
}, {
    "title": "Loco -romeo Santos Ft Enrique Iglesias. X O",
    "server": "soundcloud",
    "id": "CxYdHw4f5fsg",
    "rating": 47.0588235294,
    "download": "request",
    "size": "39.07 MB",
    "duration": "03:52"
}, {
    "title": "Enrique Iglesias - Bailando (mambo Remix) By Dj-napoles",
    "server": "soundcloud",
    "id": "ZRhFhuDi8fZx",
    "rating": 55,
    "download": "request",
    "size": "8.61 MB",
    "duration": "03:40"
}, {
    "title": "Enrique Iglesias Bailando (english) Ft. Sean Paul, Descemer Bueno",
    "server": "soundcloud",
    "id": "SxUkZ6wBJjGK",
    "rating": 48.8888888889,
    "download": "request",
    "size": "7.42 MB",
    "duration": "04:03"
}, {
    "title": "Enrique Iglesias - Bailando Ft. Gente De Zona, Sean Paul By Jeyc +(english And Spanish)",
    "server": "soundcloud",
    "id": "GPs6OD9pGj71",
    "rating": 39.2857142857,
    "download": "request",
    "size": "20.19 MB",
    "duration": "04:00"
}, {
    "title": "Enrique Iglesias - Bailando (english Version) Feat. Sean Paul (radio Rip)",
    "server": "soundcloud",
    "id": "Y84twt3p93b6",
    "rating": 44.8979591837,
    "download": "request",
    "size": "3.71 MB",
    "duration": "04:03"
}, {
    "title": "Enrique Iglesias-bailando (mambo 2014)",
    "server": "soundcloud",
    "id": "WBddU5Y5mIXo",
    "rating": 69.8412698413,
    "download": "request",
    "size": "8.40 MB",
    "duration": "03:40"
}, {
    "title": "94. Bailando - Enrique Iglesias Ft. Gente De Zona Y Descemer Bueno [[ \u00d0j Lacky ]]",
    "server": "soundcloud",
    "id": "uKoZSnLNjcoN",
    "rating": 31.7757009346,
    "download": "request",
    "size": "7.55 MB",
    "duration": "03:17"
}, {
    "title": "Enrique Iglesias   Bailando (espa\u00f1ol) Remix    Dj Venus Mix",
    "server": "soundcloud",
    "id": "7Auuj1YO2dup",
    "rating": 51.7647058824,
    "download": "request",
    "size": "3.54 MB",
    "duration": "03:51"
}, {
    "title": "Gente De Zona & Enrique Iglesias - Bailando (pedro Murcia & Dj Rajobos Batukada Edit)",
    "server": "soundcloud",
    "id": "MY7JDzfwDrHU",
    "rating": 41.8181818182,
    "download": "request",
    "size": "8.63 MB",
    "duration": "03:46"
}]

我需要将结果从最高到最低等级排序 这是我的json解码:

                            $content = $this->get($url);
                            $content = json_decode(substr(substr($content, 0, -2), 1));
                            if(empty($content)) break;
                            foreach ($content as $value) {
                                $id = $this->filterID($value->waveform_url, 'soundcloud');
//                                $download_url = 'http://media.soundcloud.com/stream/'.$download_url.'.mp3';
                                $titulo = $this->fixTitle($value->title);
                                similar_text($this->query, $titulo, $p);

                                //if(strpos($titulo, "emix") OR strpos($titulo, "dj ") OR strpos($titulo, "Dj ") )continue;
                                $this->tmp[] = array(
                                                'title'     => $this->fixTitle($value->title),
                                                'server'    => $key,
                                                'id'        => $id,
                                                'rating'    => $p,
                                                'download'  => 'request',
                                                'size'      => $this->formatBytes($value->original_content_size),
                                                'duration'  => $this->formatMilisecons($value->duration)
                                            );
                            }

欢迎任何想法

0 个答案:

没有答案