測試環境:Windows Server2003 + PHP5.3.5_TS + Apache2.2.19
建立1.php,放在localhot根目錄下,檔案內容如下:
<?php
set_error_handler(function() {
echo '出錯了';
});
set_exception_handler(function() {
echo '出錯了';
});
error_reporting(E_ALL & ~E_NOTICE);
//一段html文本
$html = '<div class="play_video"><div id="div_D65EEBE0-2955-A608-27A6-CB5713579FC2"></div></div><script type="text/javascript">swfobject.embedSWF("/flash/player.swf", "div_D65EEBE0-2955-A608-27A6-CB5713579FC2", "500", "300", "9.0.0","/flash/expressInstall.swf", {file: "/videos/2011/12/26/15/3F5F5136-0200-A646-5B48-C5C4D9ED1C3B.flv"}, {wmode:"opaque",allowfullscreen:"true", allowscriptaccess:"always"}, {id: "player_D65EEBE0-2955-A608-27A6-CB5713579FC2",wmode:"opaque"});</script>';
//一個去除script指令碼塊的正則
$reg = '#<script[^>]*>(((?!(?<![\'""])<\/?script>(?![\'""]))[\s\S])*)</script>#i';
//正則替換,去除指令碼,執行此句的時候殺死了當前的http串連,用Fiddler監控發現此串連的狀態代碼為0(網上沒有搜尋到狀態代碼為0表示什麼意思)
$html= preg_replace($reg, '', $html);
echo $html;
?>
用Chrome瀏覽器,開啟http://localhost/1.php,提示:錯誤 324 (net::ERR_EMPTY_RESPONSE):伺服器已中斷連線,且未發送任何資料。