Jump to content

Recommended Posts

Hello people (And regex gurus)!

I am working on some project now, and I have a problem which needs regex, I really need some help ..

 

Right now, WP is printing this source :

 

<!--Start krembo99 horiz navigation bar-->
<ul id="menu" class="sf-menu">	
<li class="cat-item cat-item-6"><a href="http://www.xxxx.org/wp/?cat=6" title="blabla">Buzziiii</a></li>
<li class="cat-item cat-item-7"><a href="http://www.xxxx.org/wp/?cat=7" title="blabla">Competitionsornot</a>
<ul class='children'>
<li class="cat-item cat-item-14"><a href="http://www.xxxx.org/wp/?cat=14" title="blabla">tesdrtf</a></li>
<li class="cat-item cat-item-13"><a href="http://www.xxxxxx.org/wp/?cat=13" title="blabla">tesr566</a></li></ul></li>
<li class="cat-item cat-item-8"><a href="http://www.xxxxxx.org/wp/?cat=8" title="blabla">Events</a>
</li>
<li class="cat-item cat-item-11"><a href="http://www.xxxxxx.org/wp/?cat=11" title="Vblabla">Featured Articles</a>
</li>
<li class="cat-item cat-item-1"><a href="http://www.xxxxxx.org/wp/?cat=1" title="blabla">Uncategorized</a>
</li>
</ul>
<!--End pages navigation-->

 

I need to clean the class attribute (just wipe it off)

which means intead of (for example)

<li class="cat-item cat-item-8">

 

I need just empty

 

<li>

 

or

 

<li="myclass">

 

the first option is better....

 

 

I tried to use :

 

<ul id="menu" class="sf-menu"><?php
    $cool_cats = wp_list_categories('orderby=name&show_count=0&title_li=');
    $cool_cats = preg_replace('/\<li class\="(.*?)\"/','',$cool_cats);
    echo $cool_cats;
    ?>
</ul>

 

but it does not seem to work.

Or better put, I just do not have an idea of how to use it ...

I know for you regex gods this looks increadibly easy, but for me it is like a foreign language (although I develop php apps and plugins also ..but I am mainly css and wp person, some PHP , but not regex ...

Link to comment
https://forums.phpfreaks.com/topic/154815-need-some-help-with-regex/
Share on other sites

well then you are probably not using the right variable that holds the source. Or your source isn't what you think it is.  Or you're echoing the wrong var.  My example used $string.  There's no reason why that pattern wouldn't match and replace your li tags. 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.