This article shares with you the use of PHP to format multi-line text into JS usable format. The idea is very simple. It is recommended to everyone here for reference by friends in need.
There are many scenarios for storing and writing templates in js, such as HTML code templates for pop-up boxes, etc. JS does not support long text writing with line breaks, and must be added up line by line, such as:
The code is as follows:
var content = 'row 1
' + 'row 2
';
but cannot be written as:
The code is as follows:
var content = 'row 1
row2
';
So I processed a small piece of php code to simplify the manual typing operation.
tojs.php
Str To Js String 输入格式化的文本:
"\n")); $rows = explode("\n", $content); foreach($rows as $row) { $jsContent .= '+ \'' . $row . "'
"; } $jsContent{0} = ' '; } ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
How to convert numbers into Chinese characters in php