简体   繁体   English

数组中的正则表达式php

[英]Regex php inside array

I don't know how to work with regex.我不知道如何使用正则表达式。 I get from file_get_contents (So is a string):我从 file_get_contents 得到(所以是一个字符串):

"sources": [{"file":"https:\\/\\/www40.playercdn.net\\/98\\/0\\/Ya2t561cTjn95vvqwekm7w\\/1475599977\\/161003\\/839RHzKW43tP1DAt.mp4","label":"360p","default":"true"},{"file":"https:\\/\\/www61.playercdn.net\\/100\\/1\\/sRVvFxxRF2pk26D8D7C_1A\\/1475599977\\/161003\\/950LRfeY1xeAfNQ3.mp4","label":"720p"}] ,"logo": {

And I need to extract only我只需要提取

https:\\/\\/www40.playercdn.net\\/98\\/0\\/Ya2t561cTjn95vvqwekm7w\\/1475599977\\/161003\\/839RHzKW43tP1DAt.mp4

and

https:\\/\\/www61.playercdn.net\\/100\\/1\\/sRVvFxxRF2pk26D8D7C_1A\\/1475599977\\/161003\\/950LRfeY1xeAfNQ3.mp4

And need to know that first URL is 360p and second 720p并且需要知道第一个 URL 是 360p,第二个 URL 是 720p

Thank you谢谢

I would not use regex for this.我不会为此使用正则表达式。 Instead use json_decode to convert the data to an array.而是使用json_decode将数据转换为数组。 Json is basically string-based objects that can be easily transmitted over the internet. Json 基本上是基于字符串的对象,可以轻松地通过 Internet 传输。

$array = json_decode($data, true);

You can now use normal php array notation to get the values you want.您现在可以使用普通的 php 数组表示法来获取您想要的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM