dongpai2754 2014-07-25 19:49
浏览 26
已采纳

如何从大文本中获取部分文本

Is there any way to get get a small part of data from an array index in php?
For example, I have an array of data like:

Array(

[title] => My title

[description] =>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
Code: No Promo Code Required Begin: 2014-07-25 00:00:00 Expire: 0000-00-00 00:00:00

[link] => http://google.com )

from the above array's description index, i need the part only containing

Code: No Promo Code Required Begin: 2014-07-25 00:00:00 Expire: 0000-00-00 00:00:00

Regardless of where ever this part occours in the text data.

  • 写回答

2条回答 默认 最新

  • donljt2606 2014-07-25 20:03
    关注
    $myArray = array(
        "title" => "My Title",
        "description" => "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type
    Code: No Promo Code Required Begin: 2014-07-25 00:00:00 Expire: 0000-00-00 00:00:00",
        "link" => "http://www.gopjn.com/t/3-79115-101746-99698"
        );
    
    preg_match("/(Code.*Expire:\s\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})/", $myArray["description"], $matches);
    
    echo $matches[1];
    

    DEMO

    If there could be more than one instance of the string that you want to match, and you want to get all of them, use preg_match_all() instead.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计