Both PHP and JavaScript are beginners. There is a recent need:
For example, there is a multi-line string for PHP:
$a = <<<EOFthy38csdnblogEOF;
After passing to JavaScript is equivalent to:
var c= ' Thy38\ncsdn\nblog ';
Because the understanding of these two languages is low to do not know how Google. Just be good to find out two ways to do it yourself:
1. Escape PHP first. and then cut. Then go to JSON, then JavaScript parse, and then the concatenation with \ n.
var b=json.parse (<?php echo ' \ '. Json_encode (Explode ("\ r \ n", $a)). ' \‘‘; ?
>). Join (' \ n '); alert (b==c);
2. Arrange a hidden input on the page and give it to PHP first. Then JavaScript reads from it, and it implements the delivery of multiple rows of values.
<input type= "hidden" id= ' testphp ' value= ' <?php echo $a?> "/>var a=document.getelementbyid (" testphp "). Value;var b=json.parse (<?php echo ' \ '. Json_encode (Explode (" \ r \ n ", $a)). ' ?>). Join (' \ n '); alert (a==b); alert (b==c);
PS: The above method is in the discussion with a PHP and JavaScript program ape classmate gradually draw.
After writing the article back to think about it, the fact that the two very much around the method is also due to PHP and JavaScript multi-line string understanding.
It 's easy to understand. Far from being so complicated, direct string substitution can:
var d=<?php echo ' \ '. Str_replace ("\ r \ n", "\\n\\\n", $a). ' \‘‘; ?>;alert (D==C);
Willing to share with those who have just started learning.
Multiple lines of string in PHP are passed to JavaScript method two