PHP清除网页格式,文章自动格式化
导读:下面是赵云建站使用PHP开发制作的文章自动格式化的编辑工具,源码贴出来给大家分享。
在转载网上的文章时,经常会碰到代码冗长杂乱,布满链接的情况,另外,直接从WORD里面的文章拷贝到网页上的话,代码也会极其的冗长,非常影响浏览速度。下面是赵云建站使用PHP开发制作的文章自动格式化的编辑工具,源码贴出来给大家分享:
前台页面:
<div class="form1" id="arc_edit">
<form method="post" id="arc_form">
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>标题:</td>
<td><input type="text" name="title" class="text_m" value="" /></td>
</tr>
<tr>
<td>关键词:</td>
<td><input type="text" name="keywords" class="text_m" value="" /></td>
</tr>
<tr>
<td valign="top">描述:</td>
<td><textarea class="area_m" name="description"></textarea></td>
</tr>
<tr>
<td valign="top">正文:</td>
<td><input type="hidden" id="acontent" name="acontent" value="" style="display:none" /><input type="hidden" id="acontent___Config" value="" style="display:none" /><iframe id="acontent___Frame" src="lib/editor/editor/fckeditor.html?InstanceName=acontent&Toolbar=Basic" width="600" height="500" frameborder="0" scrolling="no"></iframe></td>
</tr>
<tr class="msg">
<td valign="top">提示:</td>
<td>第一步:格式化。 第二步:手工编辑。 第三步:自动加链接。 第四步:保存或编辑下一篇。</td>
</tr>
<tr class="operate2">
<td valign="top">操作:</td>
<td><a href="javascript:submitform('fat');" class="btn1">格式化文本</a></td>
</tr>
<tr class="operate2">
<td valign="top"></td>
<td valign="middle"><a href="javascript:submitform('autolink');" class="btn1">自动加链接</a> <select name="lid" style=" float:left"><option>关键词词库</option><option value="2">www.hnzymr.cn</option><option value="3">www.hnzymr.com</option><option value="4">www.hydyyy.com</option></select></td>
</tr>
<tr class="operate2">
<td valign="top"></td>
<td><a href="javascript:submitform('save');" class="btn1">保存到草稿箱</a> <input type="hidden" name="aid" value="" /></td>
</tr>
</tbody>
</table>
</form>
</div>
<script type="text/javascript">
function submitform(type){
var oEditor = FCKeditorAPI.GetInstance('acontent');
var acontent = oEditor.GetXHTML(true);
document.getElementById('acontent').value = acontent;
var form = document.getElementById('arc_form');
form.action='?m=arc&o=edit&submit=1&type='+type;
form.submit();
}
</script>
处理代码:
if(!empty($arc['content'])){
$replaces = array("/<style.*?>.*<\/style>/i" => '',
"/<img.*?>/i" => '',
"/<font.*?>/i" => '',
"/<\/font>/i" => '',
"/<strong>/i" => '',
"/<\/strong>/i" => '',
"/<span.*?>/i" => '',
"/<\/span>/i" => '',
"/<div.*?>/i" => "<p>",
"/<\/div>/i" => "</p>",
"/<table.*?>/i" => '',
"/<\/table>/i" => '',
"/<tbody.*?>/i" => '',
"/<\/tbody>/i" => '',
"/<tr.*?>/i" => '<p>',
"/<\/tr>/i" => '</p>',
"/<td.*?>/i" => '',
"/<\/td>/i" => '',
"/<ul.*?>/i" => "<p>",
"/<\/ul>/i" => "</p>",
"/<li.*?>/i" => "<p>",
"/<\/li>/i" => "</p>",
"/<h[1-6]+.*?>/i" => "<p>",
"/<\/h[1-6]+?>/i" => "</p>",
"/<a.*?>/i" => '',
"/<\/a>/i" => '',
"/<br(.*)?>/i" => "</p></p>",
"/<b>/i" => '',
"/<\/b>/i" => '',
"/<script.*?>.*<\/script>/i" => '',
"/<iframe.*?>.*<\/iframe>/i" => '',
"/style=\".*?\"/i" => '',
"/style=\'.*?\'/i" => '',
"/ /i" => '',
"/<p.*?>/i" => '<p>',
"/[( )|( )]/u" => '',
"/[\r|\n]+/" => '',
"/<p>(<p>)+/i" => '<p>',
"/<\/p>(<\/p>)+/i" => '</p>',
"/(<p><\/p>)+/i" => '',
"/<p>/i" => '<p> ',
);
foreach($replaces as $k => $v)
$arc['content'] = preg_replace($k,$v,$arc['content']);
}
关键词: php
上一篇:用php如何实现多线程并发执行多任务处理 下一篇:




