用逗号后用php插入<br/>

时间:2013-09-29 01:32:44

标签: php wordpress custom-fields

我使用以下代码从自定义字段“黑色,灰色,白色”中对文本进行排列:

<?php global $wp_query; $postid = $wp_query->post->ID; echo get_post_meta($postid, 'colors', true); ?>

我想这样告诉我:

black</br>
grey</br>
white

PHP有可能吗?非常感谢

3 个答案:

答案 0 :(得分:1)

使用str_replace():

echo str_replace(",", "<br />", get_post_meta($postid, 'colors', true));

答案 1 :(得分:0)

如果你想在“,”之后添加<br>,你可以这样做:

$text = preg_replace("/,/", "<br>", get_post_meta($postid, 'colors', true));

答案 2 :(得分:0)

str_replace(", "    ,    ", <br  />"   ,  $string) ;

格式为(“from”,“to”,“what”)