There are string definition methods in the Heredoc method in php and python:
php:
The code copy is as follows:
$sql=<<<EOD
select *
from pages
where pagename='$pn'
EOD;
python:
The code copy is as follows:
print """
This is an example of a string in the heredoc syntax.
This text can span multiple lines
"""
It is more cumbersome to splice a large number of strings without a heredoc-style operator:
Splicing method one:
The code copy is as follows:
var str = "/
Here is line one /
And line two /
Finally, line three! /
";
alert(str);
Splicing method two:
The code copy is as follows:
var __template =
'<tr>'+
'<td>#salarySN#</td>'+
'<td>#name#</td>'+
'<td>#TDR_NAME#</td>'+
'<td>#TSD_NAME#</td>'+
'<td>#WORK_STATUS#</td>'+
'<td>#isleader_display#</td>'+
'<td>'
+'<a href="javascript:void(-1)">Set role</a>'
+'</td></tr>';
JS strings need to break the original string style and process each line, which is a bit unbearable.
Give a solution:
The code copy is as follows:
function aHereDoc() {/*
Hello, World!
I am a JavaScript here document.
Use the 'hereDoc' function to extract me.
*/}
function hereDoc(func) {
return func.toString().split(//n/).slice(1, -1).join('/n');
}
console.log(hereDoc(aHereDoc));
Use func.toString() to obtain the string that needs to be processed in batches, use split(//n/).slice(1, -1) to remove the code defined by the function in the beginning and end lines, and reassemble it.