-1

I array text from custom field "black, grey, white" with this code:

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

I want show me like this:

black</br>
grey</br>
white

It's possible with PHP? Many thanks

vektor
  • 117
  • 3
  • 11

3 Answers3

1

Use str_replace():

echo str_replace(",", "<br />", get_post_meta($postid, 'colors', true));
Starx
  • 77,474
  • 47
  • 185
  • 261
0

If you want to add <br> after a "," you can do this:

$text = preg_replace("/,/", "<br>", get_post_meta($postid, 'colors', true));
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
0
str_replace(", "    ,    ", <br  />"   ,  $string) ;

The format is ("from", "to" , "what")

Burdock
  • 1,085
  • 1
  • 9
  • 22