標籤:style blog io color ar os 使用 for sp
案例:在帶行號的代碼至檔案 crop.js 中。用兩種方法去掉代碼前面的行號,帶行號的程式碼片段:
1.$(function(){2. //初始化圖片地區3. var myimg = new Image(); 4. myimg.src = $("#mypic2").attr("src"); 5. //輸出圖片資料6. $("#showSize").html(myimg.width + "×" + myimg.height);7. 8. //初始化圖片的位置,根據圖片的寬度調整左右9. $("#statistics, #picArea").css("left",$(window).width()/2-myimg.width/2);10. $("#picArea").width(myimg.width).height(myimg.height); 11. var parentWidth = parseInt($("#picArea").width());12. var parentHeight = parseInt($("#picArea").height());13. 14. //顯示滑鼠的相對於圖片的座標(左上方為(0,0))15. var offsetX = parseInt($("#picArea").css("left"));16. var offsetY = parseInt($("#picArea").css("top"));...
1. file() 函數
使用 使用 file() 函數,把每一行代碼作為數組參數儲存進一個一維數組:
$file = "crop.js";$arr = file($file);foreach($arr as $key=>$value){ $value = preg_replace("/^[0-9]*./","",$value); $arr[$key] = $value;}$str = implode("<br>",$arr);echo $str;
直接在頁面上讀出正則匹配過的內容,然後把內容拷貝進檔案
2.把正則匹配過的內容儲存至新檔案
$filename = "text.txt";$fp = fopen($filename,"r");$buffer = "";while(!feof($fp)){ $buffer .= fread($fp,1024);}fclose($fp);$buffer = preg_replace("/[0-9]+.\s/","",$buffer);$fp = fopen($filename,"w");fwrite($fp,$buffer);fclose($fp);
這是最簡單的過濾,更複雜的過濾只需要更換Regex即可。
PHP 檔案系統管理函數與 preg_replace() 函數過濾代碼