Created
May 5, 2015 06:26
-
-
Save jrean/9444d066e3572ef9eb76 to your computer and use it in GitHub Desktop.
Extract content inside delimiters
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
/** | |
* Extract content inside delimiters. | |
* | |
* @param string $start | |
* @param string $end | |
* @return string Extracted content. | |
* | |
* @source | |
* http://www.bitrepository.com/extract-content-between-two-delimiters-with-php.html | |
*/ | |
protected function extract_unit($string, $start, $end) | |
{ | |
$pos = stripos($string, $start); | |
$str = substr($string, $pos); | |
$str_two = substr($str, strlen($start)); | |
$second_pos = stripos($str_two, $end); | |
$str_three = substr($str_two, 0, $second_pos); | |
return trim($str_three); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment