Last active
November 29, 2021 17:23
-
-
Save joelremix/9902470 to your computer and use it in GitHub Desktop.
PHP: get_string_between()
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
function get_string_between($string, $start, $end){ | |
$string = " ".$string; | |
$ini = strpos($string,$start); | |
if ($ini == 0) return ""; | |
$ini += strlen($start); | |
$len = strpos($string,$end,$ini) - $ini; | |
return substr($string,$ini,$len); | |
} | |
$fullstring = "this is my [tag]dog[/tag]"; | |
$parsed = get_string_between($fullstring, "[tag]", "[/tag]"); | |
echo $parsed; // (result = dog) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment