List files and get PHP comments with PHP script

3

I would like an idea if possible or a script that first read all the .php extension files from a folder by taking the PHP comment from each of the that have after File Name: .

<?php
/*
File Name: exemplo
*/
?>

and throw them all into a html tag select option

    
asked by anonymous 22.02.2017 / 19:19

2 answers

1

Solution I used.

function comment_titlePage() {
    $ap = WFOX_SITE_THEME . '/'; // PASTAS DO TEMA ATUAL

    if (is_dir($ap)) {
        // ABERTUR DA PASTA
        $dh = opendir($ap);

        if ($dh) {
            $arquivos = glob("$ap{*.php}", GLOB_BRACE);

            $mArray = array();
            foreach($arquivos as $php){
                $re = '/\<\?php\r\n\/\*\r\n(.*[A-z_])\r\n\*\//is';
                $str = file_get_contents($php);

                preg_match_all($re, $str, $matches);

                $return_matches = $matches[1][0];
                $loop_matches = preg_split("[File Name: ]",$return_matches);
                $mArray[$php] = $loop_matches[1];
            }

            return $mArray;

        }
    }
}
    
24.02.2017 / 15:00
3

Opa,

Have you tried using REGEX?

For example: [FIXED]

<?php

$re = '/\<\?php\r\n\/\*\r\n(.*[A-z_])\r\n\*\//is';
$str = '<?php
/*
File Name: exemplo
*/';

preg_match_all($re, $str, $matches);

var_dump($matches);

See if it helps.

    
22.02.2017 / 20:05