Avatar of damianb123
damianb123
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Explode variable with commas to separate lines

Hi,
    I have a value which is pulled from a MySql query which looks like this:

$rows1['gphours']

This value contains text like this:

Monday 9-5, Tuesday 10-4, Wednesday 9-4

What i need to do is perform an explode or implode and add a <br>, so the output looks like:

Monday 9-5
Tuesday 10-4
Wednesday 9-4

I can't think how to get it going....

Any help much appreciated.
PHPMySQL ServerSQL

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Marco Gasi

if you need to end up with a string you can jut do what you said:

$arr = explode(',', $rows1['gphours']);
$end_string = implode('<br>', $arr);

Open in new window

ASKER CERTIFIED SOLUTION
Randy Johnson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
damianb123

ASKER
Perfect, did the job nicely.... Thanks - I thought I was nearly there, it's been a long day, so thanks for your quick response.
Marco Gasi

Thanks for points but I was sure you would choose rjohnsonjr solutions: simpler, quicker and definitely more intelligent. My solution is intricate without reason. Please, consider to request attention to the moderator using the link immediately below the question box and award points to rjohnsonjr: he deserves points and future members could find my bad solution instead of the good one :-)
Your help has saved me hundreds of hours of internet surfing.
fblack61
Dave Baldwin

I would choose the str_replace() method also.