Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GodSaveEarth/6df584003e44271e5006d10034c7f96e to your computer and use it in GitHub Desktop.
Save GodSaveEarth/6df584003e44271e5006d10034c7f96e to your computer and use it in GitHub Desktop.
getBetween php
function getBetween($string, $start = "", $end = "", $include_start_end=false){
$pos1 = strpos($string, $start);
if($pos === false) return '';
$apos1 = $pos1+strlen($start);
$pos2 = strpos($string, $end, $apos1);
$apos2 = $pos2+strlen($end);
if($include_start_end)
return substr($string, $pos1, max(0, $apos2-$pos1));
return substr($string, $apos1, max(0, $pos2-$apos1)) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment