php preg_match返回计数

php preg_match返回计数,php,preg-match,Php,Preg Match,我有以下变量: $texttofind = "story of a test"; $paragraph = "the story of a test and a test paragraph used for testing the story of a test paragraph"; 我想使用preg_match()返回计数,在本例中为2。有什么想法吗 不需要正则表达式,只需使用: 如果确实要使用正则表达式,可以使用以下(速度较慢且不必要复杂)表达式: ec

我有以下变量:

$texttofind = "story of a test";
$paragraph  = "the story of a test and a test paragraph used for
               testing the story of a test paragraph";

我想使用
preg_match()
返回计数,在本例中为2。有什么想法吗

不需要正则表达式,只需使用:

如果确实要使用正则表达式,可以使用以下(速度较慢且不必要复杂)表达式:

echo preg_match_all('/' . preg_quote($texttofind, '/') . '/', $paragraph);

preg\u match\u all
默认情况下返回发生次数。
echo preg_match_all('/' . preg_quote($texttofind, '/') . '/', $paragraph);