I don't know if this question is so stupid but...
How can i add a newline character to a database registry?
I just want to add a new line character after the input that is shown to the user in the edit or add form.
For example:
//edit view
echo $this->Form->input('reply_above');
I want to send a mail with some information and this string should be at the top separate from the rest of the mail message by a newline.
I have tried this at the edit action in the controller:
$this->request->data['Setting']['reply_separator'].= '<br />';
But then, when i use the mail function it shows the <br /> instead of printing it. (and i really don't want to send the mail in HTML format)
The texts stored on the database don't use a <br /> for new lines. What do they use instead? I have also tried \n but it doesn't work either.
Thanks.
UPDATE
I could be able to add a new line doing this in the edit controller before saving the data:
$this->request->data['Setting']['reply_separator'].="
";
But it really doesn't look like a good solution plus i can not add more than one newline with this method.
Any solutions?
This is your new line character: "\n".
Edit: Be sure to use double quotes not single quote.
Related
I am using a text area field in Salesforce as a RecipientNote for a Docusign envelope created using a custom button in Salesforce.
The syntax below handles any commas or special characters, but I'm unable to find the correct syntax to preserve any linebreaks in the Program_Exception_Notes__c field.
;RecipientNote~{!JSENCODE(URLENCODE(SUBSTITUTE(Sales_Program_Info__c.Program_Exception_Notes__c,",","_COMMA_")))}
I have tried the following but none worked. Any ideas?
'{!SUBSTITUTE(JSENCODE(URLENCODE(SUBSTITUTE(Sales_Program_Info__c.Program_Exception_Notes__c,",","_COMMA_"))),"%0D%0A","\\n")}'
'{!JSENCODE(URLENCODE(SUBSTITUTE(SUBSTITUTE(Sales_Program_Info__c.Program_Exception_Notes__c,"\r\n","\\n"),",","_COMMA_")))}'
I would process your text in a couple of steps in jscript.
first break the text into an array of string lines
escape characters you are looking to correct
then reassemble using the "\n" when you put it back together into a var
Then after all that, URL and JS encode that string variable.
How to add blank line between two lines of text in webcal event's description? This \n\n doesn't work.
It might help if you would provide a full iCalendar stream but, assuming you encoded them correctly, using "\n" is the only way to express intentional line break. Did you try to display your event using different clients ?
I have this problem:
I have an HTML textarea which is filled by the user. (And he can press The enter button to go on a new line).
Then I take The value of The textarea using the command:
document.getElementById("textareaCommento")
And I pass The value to the servlet using an XmlHttpRequest.
In The servlet I save this value in a database.
Since this point I have no problems...
Then, in another part I want to get The values from The database. Using a servlet I make this query
Select * from comments
And I transform the results in json. Here I have The problem... The newline character makes my JSON string invalid. For example:
"Comment":"hello
Word"
How can I do?
Thanks in advance!
You have to replace the \n character from database to something like <br/>
For the replace see replace \n and \r\n with <br /> in java
this CSS worked for me,
white-space: pre-line;
You should be able to url encode your values so hello world would actually become "hello%20world", to do it in java see here:
Encoding URL query parameters in Java
To do it in javascript see here:
Encode URL in JavaScript?
I have a comment box and when somebody presses enter, Cake will put a \n (line feed) into the database. When I retrieve this from the db, it is displayed just like \n instead of an actual break or in HTML a .
There seems to be no option for handling \n, which I cannot understand because it is common to push enter in a textarea. What am I doing wrong?
Thanks
Chris
you forget that there are php functions covering that :)
nl2br() is what you are looking for
echo nl2br(h($data));
NOTE:
h() is for security reasons. always use h() first, than nl2br().
you dont need h() if you have html content. h() is only for plain text.
TIP: you can even enhance your bake templates to automatically display it correctly - see http://www.dereuromark.de/2010/06/22/cake-bake-custom-templates/ for details
You can also try
echo str_replace("\\n", "<br />", $variable);
CakePHP has it's own method for that:
TextHelper::autoParagraph(string $text)
Check the documentation: https://book.cakephp.org/2.0/en/core-libraries/helpers/text.html
Newbie question here.
I have a web form with a text area and naturally users will enter newline characters also. I am storing this form to a table in the DB. I also have to create a report from this. So I dump the table to text and am trying to parse it. The delimiters for me between multiple records is a new line character. But the new line character in the text area is throwing my script off.
I am sure someone must have run into this before. Can you suggest me ideas as to how to deal with this?
I tried having the text from the text area in double quotes but that will complicate my parsing logic. I was wondering if there is an easier way to deal with this.
I think the simple answer is some form of escaping.
You could do some find/replace in the SQL, such as REPLACE(thetext, '\n', '\\n'), or if the newlines are not important, you could do REPLACE(thetext, '\n', ' ')
Recently ran into the same issue. Your best best is to replace the newline characters during the data dump (or before the data gets to your database) with something else. I opted for something like // or <br> so that I can recover the new lines later.
I was trying to build one forum. The problem was when some user enters HTML. It would get translated when you display his post. And I was not able to move to next line when displaying his post. This might help you. I'm using PHP by the way.
$pattern = array('/</','/>/','/\n/');
$replace = array('<','>','<br>');
$post = preg_replace($pattern,$replace,$post);