私は試してみましたが、私は困惑しています。次のシナリオがあるとします。
$string = "Jenny's garden is one of the best in town, it has lush greens and colorful flowers. With what happened to her recently, she could use a new sprinkler system so that she does not have to over exert herself. Perhaps Joel can sell that extra bike to raise money or perhaps put up a garage sale.";
$keyword = "recently";
$length = 136;
// when keyword keyword is empty
$result = "Jenny's garden is one of the best in town, it has lush greens and colorful flowers. With what happened to her recently, she could use a (snip)";
// when keyword is NOT empty
$result = "(snip)it has lush greens and colorful flowers. With what happened to her recently, she could use a new sprinkler system so that she does not h(snip)";
私がやろうとしているのは、$result に示されている文字列の抜粋を取得することです。おそらく、キーワードの最初の出現を中心にしています (存在する場合)。substrとstrposを使用してphpでこれを達成する方法に困惑しています。ヘルプ?