I found this function which finds data between two strings of text, html or whatever.
How can it be changed so it will find all occurrences? Every data between every
One possible approach:
function getContents($str, $startDelimiter, $endDelimiter) {
$contents = array();
$startDelimiterLength = strlen($startDelimiter);
$endDelimiterLength = strlen($endDelimiter);
$startFrom = $contentStart = $contentEnd = 0;
while (false !== ($contentStart = strpos($str, $startDelimiter, $startFrom))) {
$contentStart += $startDelimiterLength;
$contentEnd = strpos($str, $endDelimiter, $contentStart);
if (false === $contentEnd) {
break;
}
$contents[] = substr($str, $contentStart, $contentEnd - $contentStart);
$startFrom = $contentEnd + $endDelimiterLength;
}
return $contents;
}
Usage:
$sample = 'OneaaaTwoTwoThreeFourFive';
print_r( getContents($sample, '', '') );
/*
Array
(
[0] => One
[1] => TwoTwo
[2] => Four
[3] => Five
)
*/
Demo.