Results 1 to 5 of 5

Thread: Remove final comma from list

  1. #1
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Remove final comma from list

    PHP newbie. I'm using this code

    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

  2. #2
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Use explode instead.

  3. #3
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    When I said I was a newbie I may have overstated my expertise.

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

    Code:
    get_the_category_list_excludeCat
    to using Explode.

  4. #4
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    go with this then:
    PHP Code:
    <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>

  5. The Following User Says Thank You to techietim For This Useful Post:

    msky (10-18-2009)

  6. #5
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Works perfect, thanks for the help

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •