September 29, 2013

insert </br> after comma with php

Vektor’s Question:

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

Use str_replace():

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!