Use PHP functions in JavaScript

JavaScript get_included_files

Returns an array with the file names that were included (includes require and once varieties)

1
2
3
4
56
7
8
9
1011
12
13
14
1516
17
18
19
2021
22
23
24
2526
27
function get_included_files () {
    // Returns an array with the file names that were included (includes require and once varieties)  
    // 
    // version: 909.322
    // discuss at: http://phpjs.org/functions/get_included_files    // +   original by: Michael White (http://getsprink.com)
    // %        note 1: Uses global: php_js to keep track of included files
    // *     example 1: get_included_files();
    // *     returns 1: ['http://kevin.vanzonneveld.net/pj_tester.php']
    var cur_file = {};    cur_file[this.window.location.href] = 1;
    if (!this.php_js) {
        this.php_js = {};
    }
    if (!this.php_js.includes) {        this.php_js.includes = cur_file;
    }
 
    var includes = [];
    var i = 0;    for (var key in this.php_js.includes){
        includes[i] = key;
        i++;
    }
     return includes;
}
external links: original PHP docs | raw js source

Examples

Running

1
get_included_files();

Should return

1
['http://kevin.vanzonneveld.net/pj_tester.php']

Dependencies

No dependencies, you can use this function standalone.

Open syntax issues

php.js uses JsLint to help us keep our code consistent and prevent some common bugs.

Eventually we want all code to pass or at least take into consideration most fixes suggested by JsLint, following this JsLint configuration we’ve decided on.


Authors

Thanks to the following developers, you get to have get_included_files goodness in JavaScript.

Comments

Add Comment
Use:
[CODE]
your_stuff('here');
[/CODE]
for proper code formatting
By submitting code here you are allowing us to use it in php.js hence dual licensing it under the MIT and GPL licenses

No comments yet. Be the first!


Contribute a New function