Hello,
I have this bit of code wich should make an good array.
But it isn't and i do not know why it isn't.
the code:
<?php
function page_arr($haystack, $needle)
{
$strlenght = strlen($haystack);
$pagesymbol = "$needle";
$symbollenght = strlen($pagesymbol);
$symbols = substr_count($haystack, $pagesymbol);
$mainarray = array();
if($symbols >= 1)
{
$i = 0;
$start = 0;
$currhaystack = $haystack;
while($i <= $symbols)
{
$end = strpos($currhaystack, $needle)+$symbollenght;
$mainarray[$i] = $start."|".$end;
$currhaystack = substr($haystack, $end, $strlenght);
$start = $end;
$i++;
}
}
else
{
$mainarray['0'] = "0|".$strlenght;
}
return $mainarray;
}
include "string2.php";
print_r(page_arr($string, "{page}"));
?>
It gives this: Array ( [0] => 0|1233 [1] => 1233|681 [2] => 681|552 )
The first(0) is fine and is correct. but the second one starts correct but the second val is incorrect. that one should be bigger.