Skip to content

Instantly share code, notes, and snippets.

@vicgonvt
Created August 4, 2018 16:20
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 vicgonvt/994dfcc31cad0c490e3e91c8bc471e20 to your computer and use it in GitHub Desktop.
Save vicgonvt/994dfcc31cad0c490e3e91c8bc471e20 to your computer and use it in GitHub Desktop.
<?php
function str_between($string, $start, $end, $innerOnly = true, $remove = false) {
if (($startPosition = strpos($string, $start)) === false || ($endPosition = strpos($string, $end)) === false) {
return false;
}
if ($innerOnly) {
$startPosition += strlen($start);
$endPosition -= strlen($end);
}
$between = substr($string, $startPosition, ($endPosition + strlen($end)) - $startPosition);
if ($remove) {
return str_replace($between, '', $string);
}
return $between;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment