artis Posted November 2, 2011 Report Share Posted November 2, 2011 (edited) Ir parasta menu struktūra: <ul> <li>txt</li> <li>txt <ul> <li>txt</li> <li>txt</li> </ul> </li> </ul> Man vajag pēdējo "</ul>" aizstāt ar "<li class="klasse"><a href="#">Quick</a></li></ul>" ...(gatavam menu pielikt beigās vēl vienu menu item). Izveidoju sekojošu kodu, ar norādi "$", lai tiek ņemts tikai pēdējais "</ul>": $menu = preg_replace('/(<\/ul>)$/', '<li class="klasse"><a href="#">Quick</a></li></ul>', $menu ); , bet kaut kā nekas nenotiek un nevaru saprast, kas vēl vajadzīgs... Edited November 2, 2011 by artis Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 2, 2011 Report Share Posted November 2, 2011 http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 Quote Link to comment Share on other sites More sharing options...
artis Posted November 2, 2011 Author Report Share Posted November 2, 2011 (edited) Kaut kāda patizla atbilde, bet ja nu kādam ko līdzīgu vēl kādreiz vajag, bez regex`iem: function str_replaceLast($s,$r,$str) { $strArr = explode($s,$str); if(count($strArr) <= 1) { return $str; } $newStr = array_pop($strArr); $str = implode($s,$strArr); $str .= $r.$newStr; return $str; } Edited November 2, 2011 by artis Quote Link to comment 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.