找到单词并在其后面回显100个字符


find the word and echo 100 character after it

我写了下面的代码。我有个问题。这个代码是为我的网站的"搜索"部分。当一个词被搜索时,我想让它在我的网站上的所有文本中找到100个字符。例如,当我搜索单词"universe"时,我想让包含这个单词的所有文本在它之后的100个字符:

("宇宙"存在死亡;人是生下来的,最后都自然地死去;世界没有创造者,因此,也就没有……

你能告诉我怎么做吗?
<div>
  <div class="title"><a  href="/html/Article/View/id/<?php echo $data['id']?>"><?php echo $data['title']?></a></div>
  <div class="description"><?php echo $description;?></div>
</div>

在打印结果时使用以下命令

我想$description是你的全部内容。

使用下面的

<?php echo substr($description,strpos($description,"universe"),100); ?>

让我知道它是否有效

使用正则表达式:

$text = 'xx universe12345678912345';
preg_match('/(universe.{0,100})/siu', $text, $matches);
var_dump($matches);

返回可选的字符串,其后最多100个字母。你可以抓取更多,然后删除/关闭html标签