phpで作ったサイトのサイトマップを自動で作成方法を探していまして、
ネットを参考に下記の方法で書き出しています。
php
1$dir = './'; 2$result = getFileList( $dir ); 3 4function getFileList( $dir ) { 5 $files = glob( rtrim( $dir, '/' ) . '/*'); 6 $list = array(); 7 foreach ( $files as $file ) { 8 9 if( !preg_match( '/\/(src|sitemap|includes|error|cache)\//', $file ) ) { 10 if ( is_file( $file ) ) { 11 $list[] = $file; 12 } 13 if ( is_dir( $file ) ) { 14 $list = array_merge( $list, getFileList( $file ) ); 15 } 16 } 17 } 18 return $list; 19}
いろいろな設定ファイルがあるため、
階層を持つファイルのみ出力したいと考えています。
php
1$files = glob( rtrim( $dir, '/' ) . '/*');
の部分を
php
1$files = glob( rtrim( $dir, '/' ) . '/*/*');
に変えたら一階層目までしか取得できませんでした。
また、
php
1if( !preg_match( '/\/(src|sitemap|includes|error|cache)\//', $file ) ) {
で除外したいディレクトリ名を指定しています。
合ってるでしょうか?
よろしくお願いします。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/07/22 07:13