Log in

View Full Version : Remove final comma from list



msky
10-17-2009, 08:34 PM
PHP newbie. I'm using this code


<li class="amenities"><u>Amenities</u> (may vary by season):
<?php
foreach((get_the_category_excludeCat()) as $cat) {
if (!($cat->cat_name=='')) echo $cat->cat_name . ', ';
}
?></li>

to print this:

Amenities (may vary by season): fireplace, jacuzzi/hot tub, kitchen/kitchenette, pets allowed, smoke free, waterfront,

How do I stop the final comma from printing?

thanks

techietim
10-17-2009, 10:12 PM
Use explode instead.

msky
10-17-2009, 10:56 PM
When I said I was a newbie I may have overstated my expertise.

I just don't see how I get from the function


get_the_category_list_excludeCat

to using Explode.

techietim
10-18-2009, 12:54 AM
go with this then:


<li class="amenities"><u>Amenities</u> (may vary by season):
<?php
$arr = get_the_category_excludeCat();
$arr_length = count($arr);
for($i = 0; $i < $arr_length; $i++)
{
if($i > 0)
{
echo ', ';
}
echo $arr[$i]->cat_name;
}
?></li>

msky
10-18-2009, 02:54 AM
Works perfect, thanks for the help