How can I get a new line in a textarea? - php

I have a textarea that I need to put a new line into with some dashes above. I have tried nl2br but that just echos the <br> tag. I have also tried to concat the \n but it is ignored.
What this is for is an email like system. When the user replies to an email, I want the old message below with a seperator like a few dashes. I can't get this to work though.
new message starts here
--------------
old message here
Can someone please give a hand?
Thanks.

Try a return character: \r
According to this article, the \n newline character should work. What is happening when you are inserting the \n character into the string using double quotes?
This works for me:
<textarea>test
testing</textarea>
it properly creates the next line. Check to make sure your source code looks something like that, with n actual line break in the source where you want it to be.

Related

Line break gets replaced with rn in php

So, I have a taxtarea where the user makes a blog post but when the user submits it their line breaks get replaced with a 'rn' and I don't know why. I thought it was the php script but when I rewrote it and after taking away the str_replaces' it still replaced a new line with a rn.
What is happening?
In textarea just like any Text Editor, New Line are carriage (\r) or newline feed (\n) characters or combination of the two (depending on the OS). To convert these characters to linebreak of HTML, use the nl2br() of PHP.
Check PHP Manual for reference.
Try removing any stripslahes(). Stripslashes removes any backslashes and forward slashes. For example, line breaks are being sent as \n or \r and the stripslashes() takes away the backslashes in those, so that's why it says 'rn'.
I had this very problem, and this solution helped me. Good luck!

PHP Detect 1 or more unicode spaces only

I have searched in vain to find a fix for this issue. I have an editable field in a web page that contains a user entered space. When I copy the space and enter it into a program called IVI32 which I guess you would call a Unicode text program, I get the following info.
The space character is defined as FFFE2000. I need to detect when this field has one or more of these spaces and nothing else. I have tried the following with preg_match:
'/\s+/u'
'/^[0 :-]+$/ '
'/\A\s*\z/'
Nothing works and I am completely stumped. Any help from some Unicode experts out there will be greatly appreciated.
There was an error in my code which was preventing anything from working properly (the product of no time off!). Here's what works for anyone else who might want to detect if an element contains only whitespace that cannot be eliminated by php trim();
if(!preg_match('/\\s/', $test_string)):-do something-
if(!preg_match('/\s+/u', $test_string)):-do something-
if(!preg_match('/[\pZ\pC]+/u', $test_string)):-do something-
For anyone who is interested the space is pasted immediately after the end of this sentence.
Would this work?
preg_match('/^ +$/', $subject);
Match a single or more spaces? Because \s will also match nonbreaking spaces, tabs, and newlines.
Have a try with:
/\p{WhiteSpace}/

Converting \n in C# to a new line in PHP

I am re-wrting this agian as people dont seem to understand what i want.
I am presenting a table with information from my SQL database. When i insert into my SQL database i add
\n
so when i 'draw' the database i can just replace it with
<br>
and it will add a new line. Heres what i tired and it doesnt seem to work:
But that doesnt seem to work, it wont replace the strings, but if i replace '$row['Info']' with something like "Hello \n Test" it will print hello and Test onto seperate lines.
In your string replacement function, replace
"\n"
With
"\\n"
As the escaping cancels the first one out.

SQL Insert Into with HTML <p> tag

I have a text field that inserts its content into an SQL table. Often, I will want this content to have <p> html tags within, based on line breaks in the text field. I have tried doing a replace before inserting:
str_replace("</p><p>", "\n", $_POST["body"]);
and I have tried doing a replace with escape characters:
str_replace("</p><p>", "\n", $_POST["body"]);
with no success. Meaning they still appear as text field line breaks. There is no security issue as the field can only be accessed by an administrator. Thank you for your help.
it seems both times you are trying to replace contrary - a </p><p> to \n which obviously fails
try to swap str_replace argumants.
I don't understand what SQL has to do here though
How about replacing each separately?
str_replace(array("</p>", "<p>"), array("\n","\n"), $_POST["body"]);
I think the problem is in " latter, like google, try replacing it with ' or call function addslashes() on your text.

Inserting Newline from XML to Database

I am trying to parse this xml document in which a newline is required for certain fields and must be inserted into the database with the newline. But I've been running into problems.
1)First Problem: \n Character
The first problem I had was using the \n like below.
<javascript>jquery_ui.js\nshadowbox_modal.js\nuser_profile.js\ntablesorter.js</javascript>
The problem was in the database the field came out ot be jquery_ui.js\nshadowbox_modal.js\n... and when output into html it was jquery_ui.jsnshadowbox_modal.jsn...............
2) Then I tried actually having newlines in the xml
<javascript>jquery_ui.js
shadowbox_modal.js
user_profile.js
tablesorter.js</javascript>
The problem was the output become %20%20%20%20%20%20%20%20%20%20shadowbox_modal.js, and so forth. So how can I get a newline to hold from xml when entered into a database and then output with the newline still?
Remove the spaces from your second example.
You probably entered a tab and/or spaces for readability, but these get inserted too.
%20 is an urlencoded space.

Categories