douwei1904 2017-05-30 10:12
浏览 402
已采纳

PHP preg_match匹配多个相同标签之间的文本

How to match text

$line = "study of 557 adults suffering from sleep";

from

 $content = "The International Journal of Nursing published a
<b>study of 557 adults suffering</b>
<br>
<b>from sleep</b>
disorders. In this study, music was played when they ...";

and somtimes the content can be

 $content = "The International Journal of Nursing published a
<b>study of 557 adults suffering from sleep</b>
disorders. In this study, music was played when they ...";

so i need one solution that can be applicable on both

preg_match("#<b>$line</b>#is",$content,$match);
  • 写回答

3条回答 默认 最新

  • duanmi4379 2017-05-30 10:26
    关注

    Like this? https://regex101.com/r/PDehGB/2

    $pattern = '/<b>study.*?of.*?557.*?adults.*?suffering.*?from.*?sleep<\/b>/ms';
    

    With this pattern it will take care of any new lines and still keep the $line.

    You can explode the $line on " " and build the pattern with implode(".*?", $arr)

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

报告相同问题?

悬赏问题

  • ¥20 关于#qt#的问题:Qt代码的移植问题
  • ¥50 求图像处理的matlab方案
  • ¥50 winform中使用edge的Kiosk模式
  • ¥15 关于#python#的问题:功能监听网页
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化