need help removing <ul> from this string

Discussion in 'PHP' started by fireboat786, Jul 1, 2009.

  1. #1
    Hi

    I have a sidebar in Wordpress with the following

    <h3>Links</h3>
    <?php $pages = wp_list_pages('sort_column=menu_order&title_li=&echo=0');
    $pages = preg_replace('%<a ([^>]+)>%U','<a $1>', $pages);
    $pages = str_replace('</a>','</a>', $pages);
    echo $pages; ?>
    PHP:
    The problem is that this produces HTML like

    <div class="about-all"><div class="about"><div class="about-body">
    <h3>Links</h3>
    <li class="page_item page-item-2"><a href="http://blah.com" title="About">About</a></li>

    <li class="page_item page-item-372"><a href="http://blah.com" >Audio Class </a></li>
    <li class="page_item page-item-309"><a href="blah.com" >Video Classes 1</a></li>
    <li class="page_item page-item-355"><a href="blah.com" >Video Classes 2</a></li>
    </div>
    PHP:
    I do not want bullets.. I just want <br> separators.

    Any idea how to do this?
     
    fireboat786, Jul 1, 2009 IP
  2. Wrighty

    Wrighty Peon

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could add the line:

    $pages = preg_replace("/<(\/)?li(.*)>,"", $pages);


    Try it! :)
     
    Wrighty, Jul 1, 2009 IP
  3. GreenWithEnvy

    GreenWithEnvy Active Member

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Should be someting more like this:
    $pages = preg_replace("/<(\/)?li(.*)>/U","", $pages);

    You had bad syntax and the above would be greedy and go all the way until the last > mark.

    In order to add the line breaks... change the full code to:
    <h3>Links</h3>
    <?php $pages = wp_list_pages('sort_column=menu_order&title_li=&echo=0');
    $pages = preg_replace('%<a ([^>]+)>%U','<a $1>', $pages);
    $pages = str_replace('</a>','</a><br />', $pages);
    $pages = preg_replace("/<(\/)?li(.*)>/U","", $pages);
    echo $pages; ?>
    PHP:
    May I ask what the point of $pages = str_replace('</a>','</a>', $pages); was in your code? I changed it to add the line break.
     
    GreenWithEnvy, Jul 1, 2009 IP
  4. fireboat786

    fireboat786 Active Member

    Messages:
    140
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    thanks... I accidentally left the
    $pages = str_replace('</a>','</a>', $pages);
    in...

    Thanks guys!
     
    fireboat786, Jul 1, 2009 IP