Created
May 29, 2019 05:24
-
-
Save trungpv1601/8ef72ddda900b9553bd88c2f44cfc541 to your computer and use it in GitHub Desktop.
get string between or get string from to php
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 | |
/** | |
* Get string between start => end | |
* | |
* @param $string | |
* @param $start | |
* @param $end | |
* | |
* @return string | |
*/ | |
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