0

I need to literally print \n inside of the the this.value.split

$rows .= "<textarea onkeyup='this.rows = (this.value.split(\"\n\").length||1);' ...

I cut the code short so its easier to read.

PHP parses it as a new line. How can I rewrite this string so that it will actually print \n ??

2 Answers 2

5

Two ways:

echo "\\n"; //escape it

echo '\n'; //use single quotes
Sign up to request clarification or add additional context in comments.

Comments

2

You need to backslash your backslash:

\\n

Alternatively, you could use single quotes to delimit your string, but this would mean you would have to escape all the literal single quotes.

Here is a demonstration: http://phpfiddle.org/main/code/s7g-ra9

5 Comments

Booo 5 seconds before me just bc I had to add a second part :-P
still printing blank. try it! try echoing out a textarea with that js function included
wait this is working.. i feel like something else in my code is removing the new line odd
it works when i simplify it at least. i will accept this answer when it becomes available
@Neal You snooze you lose :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.