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条)

报告相同问题?

悬赏问题

  • ¥30 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页