PHP:提取由另一个字符串中的已知字符串分隔的未知字符串

Here is a better explanation. For example I have the following:

$string = "startRANDOMSTRINGend";

"start" and "end" are known strings but "RANDOMSTRING" is unknwon. How can I extract that "RANDOMSTRING" based on what is before and after it in PHP?

Thank you.

<?php
$string = "startRANDOMSTRINGend";
if (preg_match('/^start(.*?)end$/', $string, $match) == 1) {
    echo $match[1];
}

You can use regex to extract the values between two known words like above.

The result is : RANDOMSTRING

try this

$a= "startRANDOMSTRINGend";
echo $middle = substr($a, 5, strlen($a)-8);