line-breaks

Capturing linebreaks (newline,linefeed) characters in a textarea

和自甴很熟 提交于 2019-11-29 06:07:55
问题 I have a form with a <textarea> and I want to capture any line breaks in that textarea on the server-side, and replace them with a <br/> . Is that possible? I tried setting white-space:pre on the textarea 's CSS, but it's still not enough. 回答1: Have a look at the nl2br() function. It should do exactly what you want. 回答2: The nl2br() function exists to do exactly this: However, this function adds br tags but does not actually remove the new lines - this usually isn't an issue, but if you want

Java code for wrapping text lines to a max line width

不打扰是莪最后的温柔 提交于 2019-11-29 05:33:45
Before I re-invent the wheel (poorly), I'd like to know if there is a some existing Java code for wrapping text lines to a given maximum width. Ideally it would: respect existing linebreaks break up lines that exceed a maximum length on word boundaries break up words whose length exceeds the maximum line width by inserting hyphens Edit: there are no "pixels" here, only java.lang.String. "maximum width" refers to the number of characters on a line. Apache commons has WordUtils and wrap function in it: http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/text/WordUtils

PHP closing tag deletes the line feed

你。 提交于 2019-11-29 04:05:23
I'm doing an experiment, an html preprocessor like SLIM or Jade. This is the PHP code that seems right: nav ul id: "test" li @<?= $Var; ?> li @About li @Contact This is the expected pre-processed html (yes, $Var == "Test"): nav ul id: "test" li @Test li @About li @Contact However, in the browser I get this wrong text as the pre-processor html : nav ul id: "test" li @Test li @About li @Contact Lastly, there are two ways to make it correct. Adding the break line manually: nav ul id: "test" li @<?= $Var . "\n"; ?> li @About li @Contact Writing a space after the PHP closing tag (??). Why is the

Writing TXT File with PHP, Want to Add an Actual Line Break

五迷三道 提交于 2019-11-29 03:23:37
I am writing a TXT file using PHP. I want to insert actual line breaks into the TXT file wherever necessary. I have tried all combinations of \n \r \r\n \n\r ... but these are not causing any linebreaks to appear - in most cases, I am seeing the text "\n" appear in the TXT file, with no linebreak. I have also tried chr(13). Any other ideas would be appreciated. Sounds to me like you might be using single quotes, i.e. '\n' rather than "\n" . If you wanted to continue with a single quotes bias (as you should!), two options: file_put_contents('/path/to/file.txt', 'Hello friend! This will appear

If Statement With Multiple Lines

佐手、 提交于 2019-11-29 02:55:01
I have an if statement with multiple conditions. I cannot see them all in a single window view. Is there a way to separate them on different lines or do they have to be written all in one line? The VBA line-continuation character is an underscore _ if ( _ (something) _ or (somethingelse) _ ) You can use the line continuation character _ These are all the same: If Something Or SomethingElse Or AnotherThing Then If Something Or SomethingElse _ Or AnotherThing Then If Something Or _ SomethingElse Or _ AnotherThing Then Like the above, you can break up the long set of conditions in one "IF"

How can I detect DOS line breaks in a file?

允我心安 提交于 2019-11-29 02:46:06
问题 I have a bunch of files. Some are Unix line endings, many are DOS. I'd like to test each file to see if if is dos formatted, before I switch the line endings. How would I do this? Is there a flag I can test for? Something similar? 回答1: You could search the string for \r\n . That's DOS style line ending. EDIT: Take a look at this 回答2: Python can automatically detect what newline convention is used in a file , thanks to the "universal newline mode" ( U ), and you can access Python's guess

JSP Document/JSPX: what determines how tabs/space/linebreaks are removed in the output?

喜夏-厌秋 提交于 2019-11-29 02:24:58
I've got a "JSP Document" ("JSP in XML") nicely formatted and when the webpage is generated and sent to the user, some linebreaks are removed. Now the really weird part: apparently the "main" .jsp always gets all its linebreak removed but for any subsequent .jsp included from the main .jsp, linebreaks seems to be randomly removed (some are there, others aren't). For example, if I'm looking at the webpage served from Firefox and ask to "view source" , I get to see what is generated. So, what determines when/how linebreaks are kept/removed? This is just an example I made up... Can you force a

How to make a line break on the Python ternary operator?

不想你离开。 提交于 2019-11-29 02:13:22
问题 Sometimes a line containing a ternary operator in Python gets too long: answer = 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's worth a shekel." Is there a recommended way to make a line break at 79 characters with a ternary operator? I did not find it in PEP 8. 回答1: You can always extend a logical line across multiple physical lines with parentheses: answer = ( 'Ten for that? You must be mad!' if does_not_haggle(brian) else "It's worth ten if it's

How do i remove all linebreaks?

╄→尐↘猪︶ㄣ 提交于 2019-11-29 01:33:53
I have something like this: <node TEXT=" txt A "/> <node TEXT=" txt X "/> <node> <html> <p> txt Y </p> </html> </node> <node TEXT="txt B"/> and i want to use XSLT to get this: txt A txt X txt Y txt B I want to strip all useless whitespaces and linebreaks of @TEXT's and CDATA's. The only XML-input that is giving structure to the output are the <node> -tags. The following transformation: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text"/> <xsl:template match="*"> <xsl:apply-templates select="@TEXT | node()"/> </xsl:template> <xsl:template

Split string in JavaScript and detect line break

随声附和 提交于 2019-11-29 01:29:15
问题 I have a small function I found that takes a string from a textarea and then puts it into a canvas element and wraps the text when the line gets too long. But it doesn't detect line breaks. This is what it's doing and what it should do: Input: Hello This is dummy text that could be inside the text area. It will then get put into the canvas. Wrong output: Hello this is dummy text that could be inside the text area. It will then get put into the canvas. What it should output: Hello This is