dsu89430 2015-09-15 15:36
浏览 43
已采纳

如何在等号=“标题1”后解析数据?

I have a string as follow:

$value[0]='#EXTINF:-1 tvg-name="title 1"  tvg-logo="./Logo1.png" group-title="groupTitle1",title 1';

I want to get data of tvg-name=, tvg-logo=,group-title= and another value after the last "," which is title 1 in this case. I want to place those data as variables for later use. could any one tell me best way to do it ?

  • 写回答

1条回答 默认 最新

  • doucong4535 2015-09-15 16:01
    关注

    Here's an example without using preg_match but should get you the expected result

    <?php
    function scrape_value($data, $key){
        $start = $key.'="';
        $end = '"';
        $data = stristr($data, $start); // Stripping all data from before $start
        $data = substr($data, strlen($start));  // Stripping $start
        $stop = stripos($data, $end);   // Getting the position of the $end of the data to scrape
        $data = substr($data, 0, $stop);    // Stripping all data from after and including the $end of the data to scrape
        return $data;   // Returning the scraped data from the function
    }
    $value[0] = '#EXTINF:-1 tvg-name="title 1"  tvg-logo="./Logo1.png" group-title="groupTitle1",title 1';
    echo scrape_value($value[0], 'tvg-name'); echo '<br />';
    echo scrape_value($value[0], 'tvg-logo'); echo '<br />';
    echo scrape_value($value[0], 'group-title'); echo '<br />';
    echo substr($value[0],strrpos($value[0],',')+1);
    ?>
    

    Result for tvg-name = title 1

    Result for tvg-logo = ./Logo1.png

    Result for group-title = groupTitle1

    Result for last value = title 1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在vue.config.js中读取到public文件夹下window.APP_CONFIG.API_BASE_URL的值
  • ¥50 浦育平台scratch图形化编程
  • ¥20 求这个的原理图 只要原理图
  • ¥15 vue2项目中,如何配置环境,可以在打完包之后修改请求的服务器地址
  • ¥20 微信的店铺小程序如何修改背景图
  • ¥15 UE5.1局部变量对蓝图不可见
  • ¥15 一共有五道问题关于整数幂的运算还有房间号码 还有网络密码的解答?(语言-python)
  • ¥20 sentry如何捕获上传Android ndk 崩溃
  • ¥15 在做logistic回归模型限制性立方条图时候,不能出完整图的困难
  • ¥15 G0系列单片机HAL库中景园gc9307液晶驱动芯片无法使用硬件SPI+DMA驱动,如何解决?