我正在创建一个格式工具,可以从文章中删除内容以供打印。演示可以在这里看到。完整的源代码可在此处获得。
现在工具条格式化并且还可以通过使用来保留段落nl2br
我想做的是能够将内容向左移动,并且如果内容之间有中断,则只有一个段落。
例如:
这
是 第一段
_ _第二段
变成:
这是第一段
第二段
我尝试使用正则表达式检查末尾是否有两个空格,但这不起作用。这是一些示例代码: HTML:
<form method="post" action="">
<textarea cols="68" rows="21" name="textinput"></textarea><br/>
<input type="checkbox" name="keep_paragraphs" value="true" checked /> Keep Paragraphs<br/>
<input type="checkbox" name="shift_left" value="true" /> Remove whitespace after line unless it ends in two spaces<br/>
<input type="submit" value="Submit" />
</form>
PHP:
$text= $_POST['textinput'];
$p= $_POST['keep_paragraphs'];
$lb= $_POST['shift_left'];
if(get_magic_quotes_gpc()){
$text = stripslashes($text);
// strip off the slashes if they are magically added.
}
$text = htmlentities($text);
//if we should keep formatting
if($p=="true"){
$text =nl2br($text);
}
if($lb=="true"){
$text = preg_replace('/\s+/', ' ', trim($text));
}
echo $text;
对此的任何帮助都会很棒
编辑:包括示例
POST 文本框 = “嗨,简
你今天怎么样
我希望一切都好”;
大多数文本将来自电子邮件和其他来源,基本上它需要超级性别。