Jump to content

line breaks not working


ProblemHelpPlease
 Share

Recommended Posts

I have a textarea field that has a series of number in it each on its own line(the new line made by pressing return). The data gets passed in a form back to the page which then processes it with php and explodes the content of the textarea based on a matching \r\n so that it creates an array of all the different number on each line. This works fine.I am now trying to add a new section that allows new number to be added to the textarea by clicking on a list of numbers elsewhere on the page. Clicking on one of the numbers makes it appear in the textarea. To do this I am using javascript and modifying the textarea by adding the number+"\r\n" to the innerhtml of the textarea.This works and adds the number in the textfield with a return after it but when the page tries to process the data with php the explode cannot find a match for \r\nAnyone any ideas whyIf I echo the passed data with <pre> tags to show the returns there arnt any yet in the textarea the data has returns and if I press return manually after an entry it works. The echo shows24234234 23423432432 2342343242 23423234instead of24234234\r\n23423432432\r\n2342343242\r\n23423234I think it may have something to do with javascript removing the returns or part of the returns when it returns the data to the page

Edited by ProblemHelpPlease
Link to comment
Share on other sites

Remember that different systems create line breaks with different characters. Assuming it will always be \r\n could cause trouble. A simple regex could match all 3 possibilities. I'm pretty sure \r\n|\r|\n does the job.When adding a newline in JS, I only ever use the \n sequence. Seems to work fine everywhere.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...