Both PHP and JavaScript are beginners. There is a recent need:
Let's say there's a multi-line string for PHP:
$a = <<
After passing to JavaScript is equivalent to:
var c= ' thy38\n\ csdn\n\ blog ';
Because the understanding of these two languages is low to do not know how Google, had to find out the method of two ways:
1. First escape PHP, then split, then go to JSON, then JavaScript parse, and then use \ n stitching.
2. Arrange a hidden input on the page, then give the value to it by PHP, and then JavaScript reads from it to implement the multi-line value delivery
PS: The above method is in the discussion with a PHP and JavaScript programmer students gradually drawn.
After writing the article back to think about, in fact, these two very much around the method is also derived from the PHP and JavaScript multi-line string understanding is not transparent.
Understanding is simple, far from being so complicated, the direct string substitution is the line:
var d=<?php echo ' \ '. Str_replace ("\ r \ n", "\\n\\\n", $a). ' \ ";?>; alert (D==C);
http://www.bkjia.com/PHPjc/825410.html www.bkjia.com true http://www.bkjia.com/PHPjc/825410.html techarticle both PHP and JavaScript are beginners. There is a need for this recently: let's say there's a multi-line string for PHP: $a = EOF thy38 CSDN blog EOF; After passing to JavaScript is equivalent to: Var c= ' thy ...