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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?