[英]php complex query, remove the last occurence string and html maching pattern
I have a menu items which gives the output via php to html 我有一个菜单项,它通过php到html提供输出
<ul class="menu"><li class="item5"><a href="/pgsweb/home.html"><span>Home</span></a></li><li><span><a> | </a></span></li><li class="item25"><a href="/pgsweb/about-us.html"><span>About Us</span></a></li><li><span><a> | </a></span></li><li class="item26"><a href="/pgsweb/products.html"><span>Products</span></a></li><li><span><a> | </a></span></li><li class="item27"><a href="/pgsweb/research-a-development.html"><span>Research & Development</span></a></li><li><span><a> | </a></span></li><li class="item28"><a href="/pgsweb/careers.html"><span>Careers</span></a></li><li><span><a> | </a></span></li><li class="item29"><a href="/pgsweb/contact-us.html"><span>Contact Us</span></a></li><li><span><a> | </a></span></li></ul>
that's the output and desired output is that it should not print the last " <li><span><a> | </a></span></li>
" 这是输出,期望的输出是它不应该打印最后的“ <li><span><a> | </a></span></li>
”
and that pipe is coming from the database which means it's dynamic and can be replace by - or anything anytime 而且该管道来自数据库,这意味着它是动态的,可以随时替换为-或任何方式
plus menu items are also dynamic (added/edited/removed) 加上菜单项也是动态的(添加/编辑/删除)
$this->_buffer .= // code to get the menu name with their link;
Following is the php code to display the pipes after every li 以下是在每个li之后显示管道的php代码
$this->_buffer .= '<li><span><a> ' . $spacer_start . ' </a></span></li>';
I tried to remove that last $this->_buffer by rtrim , but no success .. 我试图通过rtrim删除最后一个$ this-> _ buffer,但是没有成功..
please help 请帮忙
Thanks in advance Dave 预先感谢戴夫
Can't you prevent the last 你不能阻止最后一次
$this->_buffer .= '<li><span><a> ' . $spacer_start . ' </a></span></li>';
? ?
Otherwise remove it with 否则用
$this->_buffer = substr($this->_buffer, 0, -$length_of_last_part)
or with 或搭配
$this->_buffer = preg_replace('#<li><span><a> \| </a></span></li>$#', '', $this->_buffer);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.