Php find new line in string
This doesn't work: Show
Obviously because the string doesn't have the "\n" character in it. But how else can I check to see if there is a line break that is the result of the user pressing enter in a form field?
animuson♦ 52.7k28 gold badges139 silver badges145 bronze badges asked Feb 24, 2012 at 19:52 6 Your existing test doesn't work because you don't use double-quotes around your line break character (
Or, if you want cross-operating system compatibility:
Also note that
answered Feb 24, 2012 at 19:55
rdlowreyrdlowrey 39.3k9 gold badges76 silver badges98 bronze badges 4 line break is answered Feb 24, 2012 at 19:59
Mouna CheikhnaMouna Cheikhna 37.7k10 gold badges47 silver badges68 bronze badges 1 The most reliable way to detect new line in the text that may come from different operating systems is:
The suggested answer to check PHP_EOL
will not work if you are for example on Windows sytem and checking file created in Unix system. answered Nov 8, 2020 at 16:39
sprutexsprutex 6518 silver badges8 bronze badges Topic: PHP / MySQLPrev|Next Answer: Use the Newline Characters '\n' or '\r\n'You can use the PHP newline characters Let's take a look at the following example to understand how it basically works:
Note: The character Related FAQHere are some more FAQ related to this topic:
(PHP 4, PHP 5, PHP 7, PHP 8) nl2br — Inserts HTML line breaks before all newlines in a string Descriptionnl2br(string Parametersstring The input string. use_xhtml Whether to use XHTML compatible line breaks or not. Return ValuesReturns the altered string. ExamplesExample #1 Using nl2br()
The above example will output: Example #2 Generating valid HTML markup using the
The above example will output: Welcome Example #3 Various newline separators
The above example will output: This See Also
CGameProgrammer at gmail dot com ¶ 17 years ago
ngkongs at gmail dot com ¶ 15 years ago
N/A ¶ 13 years ago
fquffio at live dot it ¶ 8 years ago
aabaev ¶ 3 years ago
Anders Norrbring ¶ 16 years ago
gautier dot michelin at gmail dot com ¶ 2 years ago
" ", explode("\n", $string))." ";?> By exploding on new lines & adding end & begin for p, it's easy to concat with .
" ", explode("\n", $string))." ";} ?>
Collette ¶ 2 years ago
buzanits at gmail dot com ¶ 4 years ago
nl("One\nTwo leo dot mauro dot desenv at gmail dot com ¶ 7 years ago
Justinas M. ¶ 6 years ago
nl2br_preg_R($string)
chad at nobodyfamous dot ca ¶ 5 years ago
blacknine313 at gmail dot com ¶ 14 years ago
darenschwenke at yahoo dot com ¶ 8 years ago
j dot mons54 at gmail dot com ¶ 10 years ago
hyponiq at gmail dot com ¶ 15 years ago
How do you find a new line in a string?In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
Does \n work in PHP?Answer: Use the Newline Characters ' \n ' or ' \r\n ' You can use the PHP newline characters \n or \r\n to create a new line inside the source code.
What is Br in PHP?Using Line Breaks as in HTML: The
tag in HTML is used to give the single line break. It is an empty tag, so it does not contain an end tag. Syntax: Example: PHP. How do you check line breaks?To check whether a JavaScript string contains a line break, we can use the JavaScript regex's exec method. We call /\r|\n/. exec with text to return the matches of newline characters in text .
|