Jump to content

New line in JavaScript and not PHP?


Mathy

Recommended Posts

I am trying to trigger this code:

 

echo '

var sContent=parent.document.getElementById("cont").value.replace("[\f\n\r\t\v]", "[NL]");

';

 

As you can see, I am trying to make PHP ignore the string within the JavaScript replace function's parameter, so that JavaScript should handle the new lines, and PHP shouldn't. How is this possible?

Link to comment
https://forums.phpfreaks.com/topic/57619-new-line-in-javascript-and-not-php/
Share on other sites

If you use escape characters (or whitespace - \n \t \r etc) within single quotes PHP will ignore them. If you use double quotes PHP will parse them eg: \n will give a new line, \t with give a tab.

 

So the code you have provided should be working correctly. Check what your PHP is outputting by viewing the source (right click > View Source). If the output is correct then the problem maybe your javascript.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.