PHP:删除字符串中的所有序列直到点

PHP: cut out ALL sequences within a string until dot

我在 PHP 5.6 中有一个字符串,其中包含我需要提取到新字符串中的序列。但是由于我是 php.

的新手,我们在代码上遇到了困难

示例:($searchstring) "We got an example here which covers it to 99% all and this sentence is already part of it. Because this is the first Markerword: with a lot of other things like commata, special characters ä, ü, ß or % and more in it. This proper Markerword: contains more of it multiple times and in caotic characters. If the Markerword: contains this, then cut the whole sequence out - until the first dot after that markerword. And if there are other sentences or even just words inbetween or at the end or before we ignore them all."

序列介于两者之间,可能只有 1 次这样的序列或多次,如 2 次、3 次或 5 次...

序列本身总是具有可变长度和不同 words/numbers。但它以相同的模式开始和结束,即: 开始:“标记词:” 结束:“.”("Markerword:" 之后的第一个点) 在我们需要提取的序列之间没有句号。

我得到一个代码,但它只从字符串中提取一个序列(最后一个)。但如果有更多,他们 skipped/not 就被拿走了。

我的代码无法正常工作 100%:

    $resultstring = false;
if (strpos($searchstring, "Markerword:") !== false){
        preg_match('/(Markerword:([^.]+))/', $searchstring, $matches);
            $resultstring= $matches[0];
            $stopPos = strpos($resultstring, "  ");
            if ($stopPos !== false) {
            $resultstring= substr($resultstring,0,$stopPos + 1);
                }
            }

怎么才能把他们都这样去掉呢?

上述示例的预期结果: 标记词:其中包含许多其他内容,例如逗号、特殊字符 ä、ü、ß 或 % 等等。标记词:多次包含更多内容,并且使用粗体字。标记词:包含这个,然后将整个序列剪掉 - 直到该标记词之后的第一个点。"

$searchstring = "We got an example here which covers it to 99% all and this sentence is already part of it. Because this is the first Markerword: with a lot of other things like commata, special characters ä, ü, ß or % and more in it. This proper Markerword: contains more of it multiple times and in caotic characters. If the Markerword: contains this, then cut the whole sequence out - until the first dot after that markerword. And if there are other sentences or even just words inbetween or at the end or before we ignore them all.";

preg_match_all('/\bMarkerword:[^.]+\./', $searchstring, $m);
$result = implode(' ', $m[0]);
echo $result;

输出:

Markerword: with a lot of other things like commata, special characters ä, ü, ß or % and more in it. Markerword: contains more of it multiple times and in caotic characters. Markerword: contains this, then cut the whole sequence out - until the first dot after that markerword.

Regex explanation