List files and pick up PHP comments with PHP script

Asked

Viewed 110 times

3

I would like an idea if possible or a script that first reads all the extension files .php of a folder taking from each the comment PHP, that is at the beginning of the pages who have after the File Name:.

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

and played them all in one tag html select option

2 answers

3

Opa,

Already 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 you.

  • 1

    Didn’t work..

  • I made a change. See if it helps you now, and I’m sorry!

  • Thank you. From the beginning to a logic.. ;)

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;

        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.