PHP 句子搜索

PHP sentence search

是否可以通过输入首尾词来搜索句子?

示例: 我们有一句话"Hello world this is an example and here is FIRST word, or the start of a sentence that I need to take from here, and here is the LAST word, what means that everything before this word is not needed".

我想得到的: "FIRST word, or the start of a sentence that I need to take from here, and here is the LAST".

类似这样的东西,我需要它在 PHP。

我的想法是用一些数组来做到这一点,它开始保存从第一个单词到最后一个单词的单词。

问题没有任何努力,但有点有趣。这是一种无聊的老式方式

<?php

$string="Hello world this is an example and here is FIRST word,
or the start of a sentence that I need to take from here, 
and here is the LAST word, what means that everything 
before this word is not needed";

$first="FIRST";
$last="LAST";

$string=substr($string,strpos($string,$first));                 // Cut Left
$string=substr($string,0,strpos($string,$last)+strlen($last)); //  Cut Right

echo $string;

输出

FIRST word, or the start of a sentence that I need to take from here, 
and here is the LAST

但是因为你没有付出任何努力,所以不要指望有解释和/或更好的正则表达式方法:)