nl2br

How to use nl2br() to handle string with '\r\n'?

痞子三分冷 提交于 2019-11-27 06:23:54
问题 I am retrieving a product description value stored in database from admin through textarea upon form submit. When I select the description from database I get $description = $row['description']; and I would like to echo $description on main page like this: echo nl2br($description); but I see "\r\n" characters instead of making new rows. From what I've found here and on the net, your string must be used between double quotes, like this: echo nl2br("Hello, \r\n This is the description"); Now,

\n vs. PHP_EOL vs. <br>?

℡╲_俬逩灬. 提交于 2019-11-26 19:19:12
问题 In most cases, as for one interactive website, when we output multiple lines of contents to web client browser, in my opinion, <BR /> is much more preferable than other two: \n or PHP_EOL . Else, we need to use " <pre></pre> " to wrap the output content or use nl2br() to insert <BR /> before \n so as the multiple line mark can take effect in HTML. Like following example. $fruits = array('a'=>'apple', 'b'=>'banana', 'c'=>'cranberry'); // Multiple lines by \n foreach( $fruits as $key => $value

How to replace newline or \\r\\n with <br/>?

我是研究僧i 提交于 2019-11-26 13:04:53
Trying to simply replace some new lines. Have tried 3 different ways and I get no change: $description = preg_replace('/\r?\n|\r/','<br/>', $description); $description = str_replace(array("\r\n","\r","\n"),"<br/>", $description); $description = nl2br($description); These should all work but I still get the newlines. They are double: "\r\r". That shouldn't make any of these fail right? Robik There is already nl2br() function that replaces inserts <br> tags before new line characters: Example ( codepad ): <?php // Won't work $desc = 'Line one\nline two'; // Should work $desc2 = "Line one\nline

line breaks in a textarea

时间秒杀一切 提交于 2019-11-26 07:36:57
问题 I know when saving a textarea you can use the nl2br() or str_replace to change the /n to br tags etc. However what im not sure about how to insert line breaks into a textarea. I cant seem to find much about putting the data back into a textarea with those line breaks. For example I have a form where users can update fields. So the user may enter: foo bar baz When that is saved to the database it would be saved as: foo<br />bar<br />baz<br /> Now when that user goes back to that form after a

How to remove line breaks (no characters!) from the string?

最后都变了- 提交于 2019-11-26 01:07:22
This might appear to be a dupe, but rest assured it isn't - I have searched both SO as well as the rest of the web for an answer to my problem and ended up finding the same insufficient "solutions" over and over. Anyhow, here it goes: I'm saving user input from a textarea to a MySQL database (within a WordPress environment, but that ought not to matter to this problem, I believe). It is later retrieved from the DB to be shown to Admins in the backend of the site. The problem occurs when users submit text with line breaks (i.e. hit the Enter key). A sample string might look like this: Dear

How to remove line breaks (no characters!) from the string?

时间秒杀一切 提交于 2019-11-26 00:58:35
问题 This might appear to be a dupe, but rest assured it isn\'t - I have searched both SO as well as the rest of the web for an answer to my problem and ended up finding the same insufficient \"solutions\" over and over. Anyhow, here it goes: I\'m saving user input from a textarea to a MySQL database (within a WordPress environment, but that ought not to matter to this problem, I believe). It is later retrieved from the DB to be shown to Admins in the backend of the site. The problem occurs when