A. php如何清除html格式並去除文字中的空格然後截取文字
PHP清除html、css、js格式並去除空格的PHP函數
01 function cutstr_html($string,$length=0,$ellipsis='…'){
02 $string=strip_tags($string);
03 $string=preg_replace('/\n/is','',$string);
04 $string=preg_replace('/ |/is','',$string);
05 $string=preg_replace('//is','',$string);
06 preg_match_all("/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/",$string,$string);
07 if(is_array($string)&&!empty($string[0])){
08 if(is_numeric($length)&&$length){
09 $string=join('',array_slice($string[0],0,$length)).$ellipsis;
10 }else{
11 $string=implode('',$string[0]);
12 }
13 }else{
14 $string='';
15 }
16 return $string;
17 }
php 去除html標簽 js 和 css樣式
01 function clearHtml($content){
02 $content=preg_replace("/<a[^>]*>/i","",$content);
03 $content=preg_replace("/<\/a>/i","",$content);
04 $content=preg_replace("/<div[^>]*>/i","",$content);
05 $content=preg_replace("/<\/div>/i","",$content);
06 $content=preg_replace("/<!--[^>]*-->/i","",$content);//注釋內容
07 $content=preg_replace("/style=.+?['|\"]/i",'',$content);//去除樣式
08 $content=preg_replace("/class=.+?['|\"]/i",'',$content);//去除樣式
09 $content=preg_replace("/id=.+?['|\"]/i",'',$content);//去除樣式
10 $content=preg_replace("/lang=.+?['|\"]/i",'',$content);//去除樣式
11 $content=preg_replace("/width=.+?['|\"]/i",'',$content);//去除樣式
12 $content=preg_replace("/height=.+?['|\"]/i",'',$content);//去除樣式
13 $content=preg_replace("/border=.+?['|\"]/i",'',$content);//去除樣式
14 $content=preg_replace("/face=.+?['|\"]/i",'',$content);//去除樣式
15 $content=preg_replace("/face=.+?['|\"]/",'',$content);//去除樣式 只允許小寫 正則匹配沒有帶 i 參數
16 return $content;
17 }
B. phpcms 我生成靜態文件路徑是/html , 但是生成的頁面上的url也帶著html啊,怎麼能去掉這個
1 修改配置文件。找到\caches\configs\system.php 找到「html_root」這一項,然後把/html這個字元串刪除。
創建或者修改欄目時,在「生成HTML設置」中,設置「是否生成到根目錄」為 「是」
然後更新緩存,更新url更新欄目、更新內容頁面。更新首頁
C. php 把當前頁面另存為HTML格式。。
<?php
ob_start(); //打開緩沖區
echo "Oh, no no no!"; //html內容
$file = 'a.html';
$handle = fopen($file, 'w');
$ob = ob_get_contents(); //取得緩沖區內容
fwrite($handle, $ob); //保存HTML
fclose($handle);
ob_end_clean(); //清除緩沖區內容
?>
D. 刪除 public_html 文件夾下的 "default.php" 初始文件
public_html文件夾是伺服器生成的網站根目錄,下面是放所有網站文件的,以前的網站文件都會放到這個文件夾下面,刪除所有文件之後再把你的網站文件放進去就可以了,如果伺服器有緩存你也沒有許可權處理,伺服器自己會處理的。
編輯public_html目錄下的.htaccess文件,加入如下語句.如果public_html下沒有.htaccess文件,新建一#個即可.
注意:將 yourmaindomain.com修改為你的域名,將subfolder修改為你要指向的public_html下的子目錄.最#後一行中的index.php修改為你的網站的主頁名稱.(修改粗體表示的內容,其他內容不要改動)
E. php 刪除文件夾內以數字命名的.html文件,我對正則不是很了解,求代碼哈
// 函數,刪除數字命名.html文件
// 傳入參數 $path 為文件所在文件夾的路徑。
// 返回 數組-含有刪除了的文件名稱的數組,或者 false,如果傳入的路徑不準確。
function del_files($path)
{
if(file_exists($path) && is_dir($path))
{
$items=scandir($path);
$pattern="/\d+\.html/";
$count=0;
$files=array();
foreach($items as $item)
{
if(preg_match($pattern, $item)>0)
{
if(unlink("$path/$item"))
$files[]=$item;
}
}
return $files;
}
else
return false;
}
// 刪除 temp 文件夾下的數字命名的.html文件
$ret=del_files('temp');
if($ret===false)
echo '刪除失敗';
if(is_array($ret))
echo '刪除了'.count($ret).'個文件';
F. 如何用PHP刪除文件
<?php
function del_dir($dir){ //刪除目錄
if(!($mydir=@dir($dir))){
return;
}
while($file=$mydir->read()){
if(is_dir("$dir$file") && $file!='.' && $file!='..'){
@chmod("$dir$file", 0777);
del_dir("$dir$file");
}elseif(is_file("$dir/$file")){
$file_time=@stat($file); //讀取文件的最後更新時間
if(time()-$file_time>3600*24*14){
@chmod("$dir/$file", 0777);
@unlink("$dir/$file");
}
}
}
$mydir->close();
@chmod($dir, 0777);
@rmdir($dir);
}
?>
G. ecshop被掛馬,首頁index.php總是被篡改成html代碼,刪不掉改不了還。
最近9月份出來的ecshop漏洞,對於2.72 .2.73 3.0 3.6 4.0版本的sql執行getshell漏洞導致的用ecshop程序的網站被入侵 user.php被刪除 而且網站首頁總是被篡改經常是標題和描述被修改從網路搜索打開網站跳轉到一些博cai網站,應該對轉義函數進行過濾防止post提交生成php腳本木馬文件,而且這個被篡改的問題是反復性質的,清理刪除代碼後沒過多久就又被篡改了。必須要對程序漏洞的根源問題進行修復網站漏洞,清理已經被上傳的隱蔽性的木馬後門。
如果對程序代碼不熟悉的話建議找專業做網站安全公司來處理此問題,國內推薦Sinesafe,綠盟,啟蒙星辰等等。
H. thinkphp5如何用html文件刪除數據
1.用bootstrap列表展示數據。
2.增加刪除按鈕
3.文檔里刪除數據 Db::table('think_user')->delete(1);
I. php使用正則表達式去掉html中的注釋方法
最近在項目中在需要輸出瀏覽器中的源文件需要去掉html中的注釋,在網上看了很多的方案,不過很多的答案都是一樣的,並不能解決我的問題,於是就自己寫正則表達式,也對正則有了更加深刻的理解。
首先比較基礎的是:
$a
=
'<!--ceshi-->ceshi';
$a
=
preg_replace('#<!--.*-->#'
,
''
,
$a);
var_mp($a);
上面的代碼會輸出ceshi。
但是如果是下面的字元串的話,就不能達到我們希望的效果了
$a
=
'<!--ceshi-->ceshi<!--ceshi-->';
$a
=
preg_replace('#<!--.*-->#'
,
''
,
$a);
var_mp($a);
於是我們就把匹配規則改成如下的格式
preg_replace('#<!--.*?-->#'
,
''
,
$a);
但是在html中如果有<!--[if
lt
IE
9]>ceshi<![endif]-->這樣的代碼的話是不能去掉的,所以我們需要改進匹配規則,改成以下的格式
preg_replace('#<!--[^\!\[]*?-->#'
,
''
,
$a);
又接著如果html中有<script><!--ceshi//--></script>的代碼,我們又需要改一下我們的匹配規則了,改成了以下格式
preg_replace('#<!--[^\!\[]*?(?<!\/\/)-->#'
,
''
,
$a);
這樣的話我基本上就去掉了我需要去掉的html的注釋了!
以上就是小編為大家帶來的php使用正則表達式去掉html中的注釋方法全部內容了,希望大家多多支持腳本之家~