30 seconds of PHP

  Back to Home

firstStringBetween

stringbeginner

Returns the first string there is between the strings from the parameter $start and $end.

Use trim() and strstr() to find the string contained between $start and $end.

function firstStringBetween($haystack, $start, $end)
{
  return trim(strstr(strstr($haystack, $start), $end, true), $start . $end);
}