【发布时间】:2013-08-30 07:43:47
【问题描述】:
我正在从 url 获取内容并将它们存储在数据库中。 在此之前,我将所有内容转换为纯文本。 为此我做了这个。
我想在所有段落之后添加新的额外行。
我试过了,结果不是很清楚..
$string = "<p>As a result, his move to Microsoft has raised many questions about the Redmond-based company's plans in the PC gaming space.</p><p>With the Xbox One launch looming, Microsoft has greatly de-emphasized PC gaming of late. </p><p>Holtman's hiring could signal a renewed emphasis on the computer, though.</p>
在我看来,一个来自 Valve 的人似乎在游戏领域没有同行,相对于真正强大的 B2C [企业对消费者] 关系可能表明这一点的重要性正在上升Arcadia Investment Corp. 董事总经理 John Taylor 说。
" ;$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);
// remove excess whitespace
// looks for a one or more spaces and replaces them all with a single space.
$string = preg_replace($search, '', $string);
$string = preg_replace('/ +/', ' ', $string);
// check for instances of more than two line breaks in a row
// and then change them to a total of two line breaks
$string = preg_replace('/(?:(?:\r\n|\r|\n)\s*){2}/s', "\r\n\r\n", $string);
file_put_contents('testing.txt', $string );
【问题讨论】:
-
你能给我们一个你正在寻找的样本输入和输出吗?
-
@C.Malet 我添加了示例测试。谢谢..
标签: php string string-parsing plaintext