如何更改 PHP 替换功能?
add_filter('wp_list_categories', 'myCatNoBrk', 10, 1);
function myCatNoBrk($OrgCat) {
$CatNoBrk = preg_replace('/<br \/>/',',',$OrgCat);
return $CatNoBrk;
}
您好,这是 WordPress 函数的一部分,它将用逗号替换 html 分隔符。我如何改变它以在每个元素周围删除和添加“x”?
换句话说: 输出代码类似于
<a href="xxx">cat1</a><br>
<a href="xxx2">cat2</a><br>
and so on
我想将其更改为仅显示 ('cat1','cat2') 数组定义
示例输出:
<?php $grades_array = array('a+','a','a-','b+','b','b-','c+');?>
add_filter('wp_list_categories', 'myCatNoBrk', 10, 1);
function myCatNoBrk($OrgCat) {
$CatNoBrk = preg_replace('/<br \/>/',',',$OrgCat);
return $CatNoBrk;
}
Hello, this is part of a wordpress function that would replace html breaks with commas. How could I alter this to also remove and add 'x' around each element?
in other words:
The output code is something like
<a href="xxx">cat1</a><br>
<a href="xxx2">cat2</a><br>
and so on
I'd like to change this to show only ('cat1','cat2') for an array definition
example output:
<?php $grades_array = array('a+','a','a-','b+','b','b-','c+');?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是 100% 确定您要实现的目标,但这里有一个替换函数,可以让您指定要替换中断标记的内容 (
)
更新:
试试这个
I am not 100% sure what you are trying to achieve, but here's a replacement function that lets you specify what you are putting in place of the break tags (<br />)
UPDATE:
try this