Created
August 4, 2018 16:20
-
-
Save vicgonvt/994dfcc31cad0c490e3e91c8bc471e20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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