我正在创建一个格式化工具,用于从要打印的文章中去除内容。演示可以看到here。完整的源代码可用here。向左格式化文本
现在工具条格式化,也可以通过使用nl2br
保留段落我想要做的是能够将内容左移,只有在内容之间有中断时才有段落。
例如:
This
is
the
first
paragraphSecond Paragraph
变为:
this is the first paragraph
Second Paragraph
我用正则表达式来检查是否有结尾处有两个空格,但没有奏效尝试这个。下面是一些示例代码: 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 textbox = "Hi Jane
How are You doing today
I hope all is well";
最文本将来自电子邮件和其他来源,基本上它需要超级的性别。
这似乎失败:http://codepad.org/N2dZ1GSP – BandonRandon 2011-03-12 23:44:45
更正,它现在必须工作。 – 2011-03-13 05:20:07
它似乎在键盘上工作,但不是在我的实际软件上是'htmlentities','stripslashes'或'nl2br'去做格式化和打破preg_replace? – BandonRandon 2011-03-13 06:19:17