A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearConvert string value into html format in php - page 1
User InfoPosts
Convert string value into html format in php#1
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?"

posted date: 2009-04-14 22:58:00


Re: Convert string value into html format in php#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-14 22:58:01


Re: Convert string value into html format in php#3
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

posted date: 2009-04-14 23:01:00


Re: Convert string value into html format in php#4
Keep in mind this will only convert the carriage returns (enter characters) into <br /> tags.

posted date: 2009-04-14 23:03:00


Re: Convert string value into html format in php#5
@Mladen Mihajlovic: No it doesn’t. It adds a HTML line break to every physical line break sequence: \r\n, \n and \r<br />\r\n, <br />\n and <br />\r

posted date: 2009-04-15 02:58:00


Re: Convert string value into html format in php#6
$string = "Hello World!! How are you?";echo nl2br($string);

posted date: 2011-04-26 11:56:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.