php实现格式化多行文本为Js可用格式
js里现在存写模板的场景好多,如:弹框类的html代码模板等,js不支持换行的长文本写法,必需要一行行的加起来,如:
代码如下:
var content = '
+ '
而不可以写成:
代码如下:
var content = '
于是小加工一php小段代码,简化手工打的操作。
tojs.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
.content-box { border: 1px #f0f0f0 slid; border-left: 4px #e0e0e0 solid; padding: 5px 5px 5px 10px; } 输入格式化的文本:
$jsContent = ''; if(isset($_POST['content']) && $_POST['content']) { $content = strtr(htmlspecialchars($_POST['content']), array("\r\n" => "\n")); $rows = explode("\n", $content); foreach($rows as $row) { $jsContent .= '+ \'' . $row . "' } $jsContent{0} = ' '; } ?> 格式化后的结果: |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft