user1546650
user1546650

Reputation: 59

Formatting a string in php

Can anyone help with this formatting. I have a paragraph in a database with says (for example) 'black;blue;green' and I want to call it from the db and the format all the ; to be new lines \n.

so it becomes

black 
blue 
green

Any ideas?

Upvotes: 0

Views: 50

Answers (2)

Wings of anarchy
Wings of anarchy

Reputation: 3

$str = str_replace(";", "\n", $string);

Finds the ; and replaces it by newline.

Refer this for more

Upvotes: 0

Tim Fountain
Tim Fountain

Reputation: 33148

$string = str_replace(';', "\n", $string);

Upvotes: 5

Related Questions