gjh42:
After some private discussion, here is a solution for adding a new class tag to every third <li>. It is a generic function that can be applied in many different situations, with appropriate parameters.
// posted in user comments on strpos() in the php manual
//strnposr() - Find the position of nth needle in haystack.
//alt version - slightly faster, more correct result
function strnposr($haystack, $needle, $occurrence, $pos = 0) {//find the position of nth needle in haystack.
return ($occurrence<2)?strpos($haystack, $needle, $pos):strnposr($haystack,$needle,$occurrence-1,strpos($haystack, $needle, $pos) + 1);
}
//new function
//replace every nth occurrence of $needle with $repl, starting from any position
function str_replace_int($needle, $repl, $haystack, $interval, $first=1, $pos=0) { //gjh42 20101213
$firstpos = strnposr($haystack, $needle, $first, $pos);
if ($firstpos === false) return $haystack;
$nl = strlen($needle);
$qty = floor(substr_count($haystack, $needle, $firstpos + 1)/$interval);
do { //in reverse order
$nextpos = strnposr($haystack, $needle, ($qty * $interval) + 1, $firstpos);
$qty--;
$haystack = substr_replace($haystack, $repl, $nextpos, $nl);
} while ($nextpos > $firstpos);
return $haystack;
}
> //$needle = string to find
> //$repl = string to replace needle
> //$haystack = string to do replacing in
> //$interval = number of needles in loop; last in each loop iteration will be replaced
> //$first=1 = first occurrence of needle to replace (defaults to first)
> //$pos=0 = position in haystack string to start from (defaults to first)
> ```php
$menulist = str_replace_int('submenu', 'submenu newRow', $menulist, 3, 4);
Just had a go at implementing first trading's version of drop down menu. Amazing work...Gears of War ROCKS too. Beautiful template...
Sorry for the novice question Black Belt, but i don't understand where the 2 lots of php code go.
Does "$menulist" go in "tpl_drop_menu.php"???
& do i have go create php file in "/includes/functions/extra_functions/ " for the other???.
I'm at beginning of customizin temp attempt. Site is: http://www.poliritmia.net/
& i'm a bit of a novice...you can tell right!:blush:
Cheers