使用php修改指定檔案尾碼

來源:互聯網
上載者:User

標籤:php   進階語言   字串函數   

最近要將asp尾碼的修改成php,因懶於一個個修改。又覺得php跟Qt一樣都是進階語言了,一般進階語言都有提供對獲得的內容進行增刪改查的函數。於是乎,就上網搜了下,還真不少,故些將所用心得總結下來。

目標:將目前的目錄下的asp尾碼改成php,而不影響其它“尾碼格式的檔案”,而且只是針對“當前檔案夾”,對當前檔案夾內包含的檔案夾的檔案不進行修改。

  代碼如下:

<?php function foreachDir($dirname){  if(!is_dir($dirname)) {  echo "{$dirname} not effective dir";  exit(); } $handle=opendir($dirname); //開啟目錄while (($file = readdir($handle))!==false)  //讀取目錄{ if($file!="." && $file!='..'){   if(is_dir($dirname.$file)){ echo $dirname.$file."<br/>"; //foreachDir($dirname.$file);  //如果注釋號去掉,將會遞迴修改檔案夾內的檔案夾檔案}  else{ echo "--".$dirname."/".$file."<br/>";  $temp = substr($file, strrpos($file, '.')+1);  //擷取尾碼格式    if ($temp == "asp")   {$pos = strripos($file,'.');  //擷取到檔案名稱的位置$filename = substr($file,0,$pos);  //擷取檔案名稱rename($dirname.'/'.$file,$dirname.'/'.$filename.'.php'); //替換為php尾碼格式。  }} }  } }  foreachDir('../traverseMendFilename');?>

另外:附上擷取副檔名的四種方法:http://www.jb51.net/article/29765.htm

使用php修改指定檔案尾碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.