PHP preg_匹配相同标记多次出现之间的匹配文本
如何匹配文本PHP preg_匹配相同标记多次出现之间的匹配文本,php,preg-match,Php,Preg Match,如何匹配文本 $line = "study of 557 adults suffering from sleep"; 从 $content=“国际护理杂志发表了 557例成人抑郁症的研究 从睡眠中 在这项研究中,音乐是在他们……”的时候播放的; 有时,内容可以是 $content = "The International Journal of Nursing published a <b>study of 557 adults suffering from sleep<
$line = "study of 557 adults suffering from sleep";
从
$content=“国际护理杂志发表了
557例成人抑郁症的研究
从睡眠中
在这项研究中,音乐是在他们……”的时候播放的;
有时,内容可以是
$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 ...";
$content=“国际护理杂志发表了
557例成人睡眠障碍的研究
在这项研究中,音乐是在他们……”的时候播放的;
因此,我需要一个解决方案,可以适用于两者
preg_match("#<b>$line</b>#is",$content,$match);
preg_match(#$line#is“,$content,$match);
像这样吗
$pattern='/study.*-of.*-557.*-成人.*-患有睡眠/多发性硬化症;
使用这种模式,它将处理任何新的行,并且仍然保留$line
您可以在“”上分解$line并使用内爆(“.*”,$arr)构建模式您可以使用此正则表达式():
$line=“对557名睡眠障碍成年人的研究”;
$content=“国际护理杂志发表了
557例成人抑郁症的研究
从睡眠中
在这项研究中,音乐是在他们……”的时候播放的;
$line=内爆(“(?:[\n\s\t]*(?:)*[\n\s\t]*)*”,爆炸(“”,$line));
preg#u match(“#($line)#is”,$content,$match);
打印(匹配);
首先使用函数从字符串中删除HTML标记,然后从字符串中删除换行符
$line = "study of 557 adults suffering from sleep";
$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 ...";
echo preg_match("#$line#is",trim(preg_replace('/\s+/', ' ', strip_tags($content))),$match);
$line=“对557名睡眠障碍成年人的研究”;
$content=“国际护理杂志发表了
557例成人抑郁症的研究
从睡眠中
在这项研究中,音乐是在他们……”的时候播放的;
echo preg_匹配(“#$line#is”,修剪(preg_替换('/\s+/','',strip_标记($content)),$match);
那么您想将所有内容都放在粗体标记之间?请查看相关问题我想将两个$content中的$line与single匹配solution@alreadycoded.com这些答案都不够好吗?我们错过了什么?@AlivetoDie谢谢!:-)
$pattern = '/<b>study.*?of.*?557.*?adults.*?suffering.*?from.*?sleep<\/b>/ms';
$line = "study of 557 adults suffering from sleep";
$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 ...";
$line = implode('(?:[\n\s\t]*(?:<.+>)*[\n\s\t]*)*', explode(' ', $line));
preg_match("#($line)#is",$content,$match);
print_r($match);
$line = "study of 557 adults suffering from sleep";
$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 ...";
echo preg_match("#$line#is",trim(preg_replace('/\s+/', ' ', strip_tags($content))),$match);