[英]Insert spaces into a PHP array variable
The following code: 如下代码:
<?php $terms = get_the_term_list( $post->ID, 'projects' );
$terms = strip_tags( $terms );?>
<?php echo $terms ?>
Produces the following result: 产生以下结果:
CateringCommercialHospitality
Note the lack of spaces. 请注意缺少空格。 How do I insert spaces so the output will be: 如何插入空格,以便输出为:
Catering Commercial Hospitality
EDIT 编辑
get_the_term_list
outputs the following: get_the_term_list
输出以下内容:
<a href="http://permalink" rel="tag">Commercial</a>
Quick and dirty you could do $terms = $terms.replace(/([AZ])/g, ' $1').trim()
. 快速而肮脏的你可以做$terms = $terms.replace(/([AZ])/g, ' $1').trim()
。 Add space before every capital and strip trailing/leading spaces 在每个大写字母之前添加空格,并删除尾随/前导空格
one way is to use before after property : 一种方法是使用after属性:
<?php echo get_the_term_list( $post->ID, 'people', 'People: ', ', ' ); ?>
another way, which I used for my project : 我用于项目的另一种方式:
function findarch_portfolio_categories() {
$terms = get_the_terms( get_the_ID(), 'portfolio-category' );
if(!empty($terms)){
$portfolio_category_links = array();
foreach ( $terms as $term ) {
$portfolio_category_links[] = $term->name;
}
$on_portfolio_category = join( ", ", $portfolio_category_links );
return sprintf( esc_html__( '%s', 'textdomain' ), esc_html( $on_portfolio_category ) );
}
}
endif;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.