Last active
March 4, 2019 10:19
-
-
Save hedii/320c5aa45e11ddd765e7 to your computer and use it in GitHub Desktop.
Php get_string_between function
This file contains 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 | |
/** | |
* get_string_between function. | |
* | |
* Given a string ($string) and two delimiters ($start and $end), this function | |
* returns the substring between $start and $end. $start and $end are also | |
* removed. | |
* | |
* @link http://www.justin-cook.com/wp/2006/03/31/php-parse-a-string-between-two-strings/ | |
* | |
* @access public | |
* @param string $string | |
* @param string $start | |
* @param string $end | |
* @return string the string between $start and $end | |
*/ | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment