首页 > 后端开发 > php教程 > 求正则此文本。。 并且分开输出

求正则此文本。。 并且分开输出

WBOY
发布: 2016-06-23 14:18:23
原创
818 人浏览过

本帖最后由 zzqqdwc 于 2013-08-07 11:14:42 编辑

如果。标题 跟 URL分开




jsonCallback({qqmusic:{curtime:1375842150,issmarter:0,systemtime:1375842150,xmusicnum:2,playlist:{song:[{xqusic_id:1384750964,xctype:1,xexpire_time:0,xsong_name:"aa",xsinger_id:0,xsinger_name:"bb",xsong_url:'http://tlly.com/new/eWebEditor/UploadFile/2013870432324.mp3',xsong_dissid:0,xsong_diskname:"",xdesc:"",xquote:0,xkey:"",xclass:0,xsong_playtime:0,xsong_size:0,xis_word:0,xcopy_right:0},{xqusic_id:4886238,xctype:12,xexpire_time:1374058332,xsong_name:"你把我灌醉",xsinger_id:13948,xsinger_name:"邓紫棋",xsong_url:'http://stream6.qqmusic.qq.com/16886238.wma',xsong_dissid:430766,xsong_diskname:"你把我灌醉",xdesc:"",xquote:0,xkey:"",xclass:0,xsong_playtime:285,xsong_size:2458170,xis_word:0,xcopy_right:0,fbit:1,hd:11410487,ks:4564316,hr:320,soso:0,ape:30765297,flac:31518683,ogg:6363997}]}}})

如echo "标题" .$a. "URL" .$b. "
"


谢谢了 在线等大神 有其它的方法也可以,

回复讨论(解决方案)

$s =<<< JSsonCallback({qqmusic:{curtime:1375842150,issmarter:0,systemtime:1375842150,xmusicnum:2,playlist:{song:[{xqusic_id:1384750964,xctype:1,xexpire_time:0,xsong_name:"aa",xsinger_id:0,xsinger_name:"bb",xsong_url:'http://tlly.com/new/eWebEditor/UploadFile/2013870432324.mp3',xsong_dissid:0,xsong_diskname:"",xdesc:"",xquote:0,xkey:"",xclass:0,xsong_playtime:0,xsong_size:0,xis_word:0,xcopy_right:0},{xqusic_id:4886238,xctype:12,xexpire_time:1374058332,xsong_name:"你把我灌醉",xsinger_id:13948,xsinger_name:"邓紫棋",xsong_url:'http://stream6.qqmusic.qq.com/16886238.wma',xsong_dissid:430766,xsong_diskname:"你把我灌醉",xdesc:"",xquote:0,xkey:"",xclass:0,xsong_playtime:285,xsong_size:2458170,xis_word:0,xcopy_right:0,fbit:1,hd:11410487,ks:4564316,hr:320,soso:0,ape:30765297,flac:31518683,ogg:6363997}]}}})JS;preg_match_all('/xsong_(name|url):([^,]+)/', $s, $r);foreach($r[1] as $i=>$v) {  echo ($v == 'name' ? '标题' : 'URL') . $r[2][$i] . ($v == 'url' ? '<br>' . PHP_EOL : '');}
登录后复制
标题"aa"URL'http://tlly.com/new/eWebEditor/UploadFile/2013870432324.mp3'

标题"你把我灌醉"URL'http://stream6.qqmusic.qq.com/16886238.wma'

$s=<<<txtjsonCallback({qqmusic:{curtime:1375842150,issmarter:0,systemtime:1375842150,xmusicnum:2,playlist:{song:[{xqusic_id:1384750964,xctype:1,xexpire_time:0,xsong_name:"aa",xsinger_id:0,xsinger_name:"bb",xsong_url:'http://tlly.com/new/eWebEditor/UploadFile/2013870432324.mp3',xsong_dissid:0,xsong_diskname:"",xdesc:"",xquote:0,xkey:"",xclass:0,xsong_playtime:0,xsong_size:0,xis_word:0,xcopy_right:0},{xqusic_id:4886238,xctype:12,xexpire_time:1374058332,xsong_name:"你把我灌醉",xsinger_id:13948,xsinger_name:"邓紫棋",xsong_url:'http://stream6.qqmusic.qq.com/16886238.wma',xsong_dissid:430766,xsong_diskname:"你把我灌醉",xdesc:"",xquote:0,xkey:"",xclass:0,xsong_playtime:285,xsong_size:2458170,xis_word:0,xcopy_right:0,fbit:1,hd:11410487,ks:4564316,hr:320,soso:0,ape:30765297,flac:31518683,ogg:6363997}]}}})txt;preg_match('/\{.+\}/s',$s,$m);$s= str_replace("'" , '"' , preg_replace('/(?<=[,{])([^,{:]+)\:/s','"$1":',$m[0]));print_r(json_decode($s,true));
登录后复制

Array
(
    [qqmusic] => Array
        (
            [curtime] => 1375842150
            [issmarter] => 0
            [systemtime] => 1375842150
            [xmusicnum] => 2
            [playlist] => Array
                (
                    [song] => Array
                        (
                            [0] => Array
                                (
                                    [xqusic_id] => 1384750964
                                    [xctype] => 1
                                    [xexpire_time] => 0
                                    [xsong_name] => aa
                                    [xsinger_id] => 0
                                    [xsinger_name] => bb
                                    [xsong_url] => http://tlly.com/new/eWebEditor/UploadFile/2013870432324.mp3
                                    [xsong_dissid] => 0
                                    [xsong_diskname] => 
                                    [xdesc] => 
                                    [xquote] => 0
                                    [xkey] => 
                                    [xclass] => 0
                                    [xsong_playtime] => 0
                                    [xsong_size] => 0
                                    [xis_word] => 0
                                    [xcopy_right] => 0
                                )

                            [1] => Array
                                (
                                    [xqusic_id] => 4886238
                                    [xctype] => 12
                                    [xexpire_time] => 1374058332
                                    [xsong_name] => 你把我灌醉
                                    [xsinger_id] => 13948
                                    [xsinger_name] => 邓紫棋
                                    [xsong_url] => http://stream6.qqmusic.qq.com/16886238.wma
                                    [xsong_dissid] => 430766
                                    [xsong_diskname] => 你把我灌醉
                                    [xdesc] => 
                                    [xquote] => 0
                                    [xkey] => 
                                    [xclass] => 0
                                    [xsong_playtime] => 285
                                    [xsong_size] => 2458170
                                    [xis_word] => 0
                                    [xcopy_right] => 0
                                    [fbit] => 1
                                    [hd] => 11410487
                                    [ks] => 4564316
                                    [hr] => 320
                                    [soso] => 0
                                    [ape] => 30765297
                                    [flac] => 31518683
                                    [ogg] => 6363997
                                )

                        )

                )

        )

)

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板