krembo99 Posted April 20, 2009 Share Posted April 20, 2009 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/154815-need-some-help-with-regex/ Share on other sites More sharing options...
.josh Posted April 20, 2009 Share Posted April 20, 2009 $string = preg_replace('~<li[^>]*>~i','<li>',$string); Quote Link to comment https://forums.phpfreaks.com/topic/154815-need-some-help-with-regex/#findComment-814221 Share on other sites More sharing options...
krembo99 Posted April 20, 2009 Author Share Posted April 20, 2009 Thanks you very much for the quick reply, however, I am affraid the function for some reason does not work well. The result of the source code remains the same, somehow It can not find the pattern... Quote Link to comment https://forums.phpfreaks.com/topic/154815-need-some-help-with-regex/#findComment-814454 Share on other sites More sharing options...
.josh Posted April 20, 2009 Share Posted April 20, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/154815-need-some-help-with-regex/#findComment-814586 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.