Home >Backend Development >PHP Tutorial >PHP implements formatting of multi-line text into JS usable format_PHP tutorial
There are many scenarios for storing and writing templates in js, such as: html code templates for pop-up boxes, etc., which are not supported by js The way to write long text with line breaks must be added up line by line, such as:
The code is as follows:
but cannot be written as:
The code is as follows:
So I processed a small piece of php code to simplify the manual typing operation.
tojs.php
4 11 12 |
Enter formatted text:<🎜>$jsContent = '';<🎜> <🎜>if(isset($_POST['content']) && $_POST['content']) {<🎜> <🎜>$content = strtr(htmlspecialchars($_POST['content']), array("rn" => "n")); $rows = explode("n", $content); foreach($rows as $row) { $jsContent .= ' '' . $row . "'"; } $jsContent{0} = ' '; } ?> Formatted result: |