str_replace to create unordered list with unique css ids

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jason660
Forum Newbie
Posts: 1
Joined: Thu Dec 02, 2010 6:58 am

str_replace to create unordered list with unique css ids

Post by jason660 »

Hello,

I am using the following code to get values and display them as an unordered list.

Code: Select all

<div class="qualifier">
<?php
    $patterns = array();
    $patterns[0] ='item1';
    $patterns[1] ='item2';
    $patterns[2] =',';

    $replace = array();
    $replace[0] ='<a class="qualifier-img"><img src="/media/catalog/image.gif" border="0"><span><strong>Text1</strong></span></a>';
    $replace[1] ='<a class="qualifier-img"><img src="/media/catalog/image2.gif" border="0"><span><strong>Text2</strong></span></a>';
    $replace[2] ='</li><li>';?>
<ul><li>
<?php    if($_product->getResource()->getAttribute('qualifier')->getFrontend()->getValue($_product)):
        echo str_replace($patterns,$replace,$_product->getResource()->getAttribute('qualifier')->getFrontend()->getValue($_product)); 
    endif; ?></li></ul><br />
</div> 
As you can see the css class is the same for each list item. What I need to do is output the values with different css classes ie. qualifier-img1, qualifier-img2 etc.

Anyone know a method for doing this?

Thanks,

j
Post Reply