0

如果我在我的 php 变量中声明了数据,我如何将 santance 从“any”复制到“Would”。

数据示例:

如果您对麦克米伦有任何疑问,我们很乐意听取您的意见。

谢谢您的帮助。

亲切的问候,卷轴。

4

2 回答 2

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];
}
于 2012-07-12T02:05:51.720 回答
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 />';
于 2012-07-12T02:06:04.317 回答