作者yuleen123 (.......................)
看板PHP
標題Re: [請益] 掃描資料夾檔案
時間Sun Jan 3 14:52:55 2010
※ 引述《herman602 (奸商)》之銘言:
: 我想要做一個PHP程式
: 掃描一個資料夾裡面的所有檔案(都是PHP檔案)
: 我知道有scandir()這個可以用
: 但是我還想抓出每一個檔案的<title> </title>之間的字
: 請問要怎麼做呢
: 感謝
我想到的是, 把每個檔案內容讀進一個變數中, 假設是 $file_content
可以使用 $file_content = file_get_contents( filename ) 來達成
之後可以用 strpos 來紀錄 <title> 和 </title> 出現的位置
$begin = strpos( $file_content, "<title>" ) + strlen("<title>");
$end = strpos( $file_content, "</title>" );
最後可以用 substr 把 <title> 和 </title> 中間的內容取出來
$content = substr($file_content, $begin, $end - $begin );
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.35.132.7
推 herman602:感謝! 我來試看看! 01/03 14:54
推 shadowjohn:推preg_match("/<title>(.*?)<\/title>/msi",$str,$m) 01/03 15:16