str_replace problem!
-
I have a function to return a category menu, I am trying to add a ‘color’ class to the returned menu variable.
Lets say we have category $i = 1 and $style=’green’
$cat_class = 'cat-item cat-item-' .$i; $amended_class = $cat_class .' ' .$style; $catlist = str_replace($cat_class, $amended_class, $catlist );This works as expected as:
cat-item cat-item-1will become
cat-item cat-item-1 greenThats great but it will replace all instances, so we then hit unlucky ’13’
cat-item cat-item-13will become
cat-item cat-item-1 green3I have tried adding a space to the $cat_class:
$cat_class = ‘cat-item cat-item-‘ .$i .’ ‘;But this does not work!
I am using the same code for category ancestors so it means that these will be doing the same and splitting the 13 if 1 and 13 are in the same tree.
Any ideas?
David
The topic ‘str_replace problem!’ is closed to new replies.