Suppose we have a

$string = “[Hello there I’m=testing]”

And we want to extract the string placed between the characters between = and ].

Here’s how to do it using PHP string functions:

BY Best Interview Question ON 18 Aug 2020

Example

$str = "[Hello there I’m=testing]";
$from = "=";
$to = "]";

echo getStringBetween($str,$from,$to);

function getStringBetween($str,$from,$to)
{
    $sub = substr($str, strpos($str,$from)+strlen($from),strlen($str));
    return substr($sub,0,strpos($sub,$to));
}

Output:
Testing