define('STARTING', 'starting string');
$ending = 'ending string';
$string = 'starting stringSomething Hereending string';
function get_anything($string, $ending, &$anything)
{
if (strpos($string, STARTING) !== 0)
{
return false;
}
if (substr($string, strlen($ending) * -1) != $ending)
{
return false;
}
$anything = substr($string, strlen(STARTING));
$anything = substr_replace($anything, '', strlen($ending) * -1, -1);
return true;
}
if (get_anything($string, $ending, $anything))
{
echo $anything;
}
The function get_anything will return false if the pattern is not found, and true if it is found. The "anything" in the middle will be returned in the third parameter.