hamobi
hamobi

Reputation: 8130

How to literally print \n in string using php

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 ??

Upvotes: 0

Views: 775

Answers (2)

user1726343
user1726343

Reputation:

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

Upvotes: 2

Naftali
Naftali

Reputation: 146310

Two ways:

echo "\\n"; //escape it

echo '\n'; //use single quotes

Upvotes: 5

Related Questions