简体   繁体   中英

PHP get_meta_tags to scan for index.php, title tags, in multiple sub folders

PHP question. I'm writing a little back-end control panel for myself for fun/practice and I want to be able to pull either the meta tags or title tag from index.php (websites) in different subfolders to insert that title in the sql db. The structure is basically www.mysite/admin/job_folder/(breaks into diff job folders here), where each job folder will have web pages with title tags or meta). The index.php is what I'm really looking for. I'm running into a problem where I'm just getting an echo of the last folder (alphabetically I'm assuming) in the array, not the whole array of folders, therefore only getting the meta tags from the last folder.

I love figuring this stuff out myself but on this for 2 days now, searched a lot, so ready to ask for help...greatly appreciated!

$index = glob(DIR_DOCS . '*' );
                foreach ($index as $path) {  //this cleaned up the array for path
                echo "$path";   //just for testing it
                }
                $tags = (get_meta_tags($path . '/index.php')); //this where I need it to split/scan diff folders for index.php files. should be an array of the paths
                $title = array($tags['title_name']); //result here will eventually go in db
                $folder = array($tags['folder_name']); //result here will eventually go in db

Your last 3 lines should be within the foreach loop. Right now the code loops through all the folders, setting $path each time, and then runs get_meta_tags at the end.

Proper indenting will help make this kind of bug more obvious in the future.

Since glob returns and array, you need to loop through $index and get_meta_tags for each array element.

$index = glob(DIR_DOCS . '*');
foreach ($index as $path) {  //this cleaned up the array for path
    echo "$path";   //just for testing it
    $tags = (get_meta_tags($path . '/index.php')); //this where I need it to split/scan diff folders for index.php files. should be an array of the paths
    $title = array($tags['title_name']); //result here will eventually go in db
    $folder = array($tags['folder_name']); //result here will eventually go in db
}

Returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error. ~ http://uk3.php.net/glob

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM