0

我找不到说明如何操作的文档。我在我的网站的搜索结果中动态显示帖子描述的一部分。

例子:

<?php
$extract = "Include all the information someone would need to answer your question.";
$search = "format";
$num = stripos($extract,$search);

$to_show = substr($extract,$num, 17);

echo $to_show;
?>

结果:

formation someone

我希望能够显示“信息”而不是“形成”。有什么建议吗?

4

1 回答 1

0

实际上正则表达式可以很好地解决您的特定问题。搜索\w*format\w*使用preg_match_all

$extract = "Include all the information someone would need to answer your question.";
preg_match_all("/\w*format\w*/", $extract, $matches);
print_r($matches[0]);

这打印:

Array
(
    [0] => information
)
于 2022-01-25T03:14:53.350 回答