Splitting an line of text?
<p>I have things saved in a database such as:</p>

<pre><code>Apple Banana Orange Pear
</code></pre>

<p>They are all saved in the database on one line, separated by spaces.</p>

<p>I want to retrieve this information from the database, and put them into html like so:</p>

<pre><code>&lt;li&gt;Apple&lt;/li&gt;
&lt;li class="alt"&gt;Banana&lt;/li&gt;
&lt;li&gt;Orange&lt;/li&gt;
&lt;li class="alt"&gt;Pear&lt;/li&gt;
</code></pre>

<p>How would I go about doing this? I've looked into explode() and then foreach, is that the best way?</p>

<pre><code>$fruits = explode(" ", $q['fruits']);

$i = 1;

foreach( $fruits as $fruit ){

    if ($i % 2 == 0){
        $alt = ' class="alt"';
    }else{
        $alt = '';
    }

    echo "&lt;li" . $alt . "&gt;" . $value . "&lt;/li&gt;";

$i++;
}
</code></pre>
