Link to home
Start Free TrialLog in
Avatar of damianb123
damianb123Flag 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.
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

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
Avatar of Randy Johnson
Randy Johnson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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.
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 :-)
I would choose the str_replace() method also.