I'm trying to get the text between two delimiters and save it into an array. I wrote this function, the problem with this code is it removes duplicates so
$this->getInnerSubstring('{2}{A}{A}{A}{X}','{', '}');
returns an array that is like
[0] =>2,
[1]=>A,
[2] =>X ,
Yet I want:
[0] =>2,
[1]=>A,
[2]=>A,
[3]=>A,
[4] =>X,
Without Regex patterns is there a substr flag that lets me keep duplicates? what's the best approach here:
function getInnerSubstring($string,$start, $end){
$s = array();
do
{
$startpos = strpos($string, $start) + strlen($start);
$endpos = strpos($string, $end, $startpos);
$s[] = substr($string, $startpos, $endpos - $startpos);
//remove entire occurance from string:
$string = str_replace(substr($string, strpos($string, $start), strpos($string, $end) +strlen($end)), '', $string);
}
while (strpos($string, $start)!== false && strpos($string, $end)!== false);
return $s;
}