Function
Get all occurrences of substring
function tkt_get_contents($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; }
Use it like so:
$string = 'any string with any repetitive html or else valid text content such as this example'; $start = ''; $end = ''; $matches_array = tkt_get_contents($string, '', ''); print_r($matches_array);
This will produce:
Array ( [0] => with [1] => else )