2015-11-06 61 views
1

我试图从给定的代码提取URL标记来提取URL标记在JSON:如何使用PHP

(function(e,a){ 
    var t={ 
     "cdn_url":"https://f.vimeocdn.com", 
     "view":1, 
     "request":{ 
      "files":{ 
       "h264":{ 
        "hd":{ 
         "profile":113, 
         "origin":"level3", 
         "url":"https://09-lvl3-pdl.vimeocdn.com/01/3164/4/115821665/722085083.mp4?expires=1446817250&token=0cc7a9f36655f3a0afff3", 
         "cdn":"level3", 
         "height":720, 
         "width":1280, 
         "id":722085083, 
         "bitrate":2583, 
         "availability":114 
        }, 
        "sd":{ 
         "profile":112, 
         "origin":"level3", 
         "url":"https://09-lvl3-pdl.vimeocdn.com/01/3164/4/115821665/722083593.mp4?expires=1446817250&token=024b83dea6d2f4e4f57e1", 
         "cdn":"level3", 
         "height":360, 
         "width":640, 
         "id":722083593, 
         "bitrate":667, 
         "availability":114 
        } 
       }, 
       "hls":{ 
        "origin":"level3", 
        "all":"https://09-lvl3-hls.vimeocdn.com/1446820550-c34bde21acdff66dc5a0a7a4a701ba220774c80e/01/3164/4/115821665/master.m3u8", 
        "cdn":"level3" 
       }, 
       "codecs":["h264"] 
      }, 
      "ga_account":"UA-76641-35", 
      "expires":3600, 
      "timestamp":1446813350, 
      "signature":"6e5fbd174b7b4503945ffa8ae800f4b5", 
      "currency":"USD", 
      "session":"60ee52a4f9a681617d768b7bf329c10867b53cfe1446813350", 
      "cookie": { 
       "scaling":1, 
       "volume":1.0, 
       "quality":null, 
       "hd":null, 
       "captions":null}, 

我试图提取SD视频网址这一个从上面的代码:

https://09-lvl3-pdl.vimeocdn.com/01/3164/4/115821665/722083593.mp4?expires=1446817250&token=024b83dea6d2f4e4f57e1 

我使用PHP可以帮助任何人! 我想下载视频,但为此我首先需要SD视频的网址。

在此先感谢! :)

+0

我不知道你有什么要求。你想从上面的json中提取url标记吗? – Doro

+0

我想从上面的文本中提取https:// url来下载该视频! –

回答

0

如果这是你需要的,可以尝试

在代码使用的
"url":"([^"]*)" 

https://regex101.com/r/tZ1iV5/2

实施例:

$re = "/\"url\":\"([^\"]*)\"/"; 
$str = "(function(e,a){var t={\"cdn_url\":\"https://f.vimeocdn.com\",\"view\":1,\"request\":{\"files\":{\"h264\":{\"hd\":{\"profile\":113,\"origin\":\"level3\",\"url\":\"https://09-lvl3-pdl.vimeocdn.com/01/3164/4/115821665/722085083.mp4?expires=1446817250&token=0cc7a9f36655f3a0afff3\",\"cdn\":\"level3\",\"height\":720,\"width\":1280,\"id\":722085083,\"bitrate\":2583,\"availability\":114},\"sd\":{\"profile\":112,\"origin\":\"level3\",\"url\":\"https://09-lvl3-pdl.vimeocdn.com/01/3164/4/115821665/722083593.mp4?expires=1446817250&token=024b83dea6d2f4e4f57e1\",\"cdn\":\"level3\",\"height\":360,\"width\":640,\"id\":722083593,\"bitrate\":667,\"availability\":114}},\"hls\":{\"origin\":\"level3\",\"all\":\"https://09-lvl3-hls.vimeocdn.com/1446820550-c34bde21acdff66dc5a0a7a4a701ba220774c80e/01/3164/4/115821665/master.m3u8\",\"cdn\":\"level3\"},\"codecs\":[\"h264\"]},\"ga_account\":\"UA-76641-35\",\"expires\":3600,\"timestamp\":1446813350,\"signature\":\"6e5fbd174b7b4503945ffa8ae800f4b5\",\"currency\":\"USD\",\"session\":\"60ee52a4f9a681617d768b7bf329c10867b53cfe1446813350\",\"cookie\":{\"scaling\":1,\"volume\":1.0,\"quality\":null,\"hd\":null,\"captions\":null},"; 

preg_match($re, $str, $matches); 

$matches[1]包含的价值,你需要

Online Demo

+0

看看我的更新 – Doro

+0

你能否提供我完整的preg_match代码来申请这个在PHP中。 –

+0

http://sandbox.onlinephpfunctions.com/code/0891043e7b9e54b526f34004372622ce0a41a5da – Doro

0

这是一个正则表达式来抓住它:

"sd":.*?"url":"([^"]*)" 

URL中的第一个(也是唯一一个)捕获组中结束。

但这是一个非常粗糙的方式得到它。我建议你得到JSON对象并使用json_decode来获得你想要的值。 (您例如HTML是不完整的,所以我不能告诉你什么是正则表达式来获得JSON对象会是什么样虽然)。

问候