Here is the actual code I'm working with:
function stripos_words($haystack,$needles_array,$pos_as_key=true)
{
for ($iz=0;$iz<sizeof($needles_array);$iz++)
{
$needles=$needles_array[$iz];
$idx=0; // Used if pos_as_key is false
// Convert full text to lower case to make this case insensitive
$haystack = strtolower($haystack);
// Split keywords and lowercase them
$needle=strtolower($needles);
// Get all occurences of this keyword
$i=0; $pos_cur=0; $pos_found=0;
while ( $pos_found !== false )
{
// Get the strpos of this keyword (if thereis one)
$pos_found = strpos(substr($haystack,$pos_cur),$needle);
if ( $pos_found !== false )
{
// Set up key for main array
$index = $pos_as_key ? $pos_found+$pos_cur : $idx++;
// Populate main array with this keywords positional data
$positions[$index]['start'] = $pos_found+$pos_cur;
$pos_cur += ($pos_found+strlen($needle));
$positions[$index]['endish'] = $pos_cur;
// find the close of the >
$pos_cur = strpos($haystack, '>', $pos_cur);
$positions[$index]['end'] = $pos_cur;
//
$positions[$index]['word'] = $needle;
$i++;
$thechars[]=$positions[$index]['start'];
$thestring[]=strlen($needle);
$num=$positions[$index]['start'];
//echo substr($haystack,$positions[$index]['start'],strlen($needle));
}
}
}
// now we do something really special
// The results will be ordered as follows arrayValue1,arrayValue1,arrayValue1,arrayValue2,arrayValue2,arrayValue2,
// therefore we have to work out which key relates to which array value :-/ (Al shits the bed!)
$amountKeys = count($thechars);
for ($i = 0; $i <= (count($thechars)/2)-1; $i++) {
$startPos = $thechars[$i]+$thestring[$i];
// find key related to current key
$endKey = ($amountKeys/2)+($i);
$endPos = $thechars[$endKey]-$startPos;
// lets make our attributes :)
$formAttributes[] = substr($haystack,$startPos,$endPos);
//echo "formAttributes = ".$formAttributes[$i]."<br>";
$htmlVariables[] = substr($haystack,$startPos-$thestring[$i],$thestring[$i]+strlen($formAttributes[$i])+$thestring[$endKey]);
//echo "htmlVariable = ".$htmlVariables[$i]."<br>";
}
print_r($htmlVariables); // THIS LINE WORKS
}
stripos_words($html,array("[MULTI(n)]","[/MULTI]"),$pos_as_key=false);
print_r($htmlVariables); // THIS LINE DOES WORK
Look at the print_r bits. I need to return the array out of the function to use further down the page.