Reputation: 43788
Any one know how to convert string value into html format in php? For Example:
$string = "Hello World!!
How are you?"
If I echo $string, it will display like this:
Hello World!!How are you?
Instead of:
Hello World!!
How are you?
Any way php can conver the $string into html format? If I input:
$string = "Hello World!!
How are you?"
Php will convert it to become:
$string = "Hello World!!<br>How are you?"
Upvotes: 1
Views: 5982
Reputation: 655845
You’re looking for the nl2br
function that adds an HTML line break tag <br />
to every physical line break sequence (\n
, \r
or \r\n
):
\n → <br />\n
\r → <br />\r
\r\n → <br />\r\n
Upvotes: 8