如果我在我的php变量中声明数据,我如何从“任意”复制到“将”。
数据示例:
如果您有任何关于麦克米伦的问题我们愿意听取您的意见。
感谢您的帮助。
亲切的问候, 卷轴。
答案 0 :(得分:1)
使用preg_match()
:
$somestr = 'If you have any questions about Macmillan we would love to hear from you.';
if (preg_match('/(\bany\b.+?\bwould\b)/i', $somestr, $matches)) {
echo $matches[0];
}
答案 1 :(得分:0)
你可以试试这个:
$string = 'If you have any questions about Macmillan we would love to hear from you.';
preg_match('/( any )(.*?)( would )/', $string, $matches);
echo $matches[0]; // any questions about Macmillan we would
编辑1
要匹配多个结果,如果存在:
preg_match_all('/( any )(.*?)( would )/', $string, $matches);
foreach($matches[0] as $value)
echo 'Found: ' . $value . '<br />';