UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

59 lines (51 loc) 1.84 kB
--- layout: page title: "JavaScript ftell function" comments: true sharing: true footer: true alias: - /functions/view/ftell:806 - /functions/view/ftell - /functions/view/806 - /functions/ftell:806 - /functions/806 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's ftell {% codeblock filesystem/ftell.js lang:js https://raw.github.com/kvz/phpjs/master/functions/filesystem/ftell.js raw on github %} function ftell (handle) { // http://kevin.vanzonneveld.net // + original by: Brett Zamir (http://brett-zamir.me) // * example 1: var h = fopen('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm', 'r'); // * example 1: fread(h, 100); // * example 1: ftell(h); // * returns 1: 99 var getFuncName = function (fn) { var name = (/\W*function\s+([\w\$]+)\s*\(/).exec(fn); if (!name) { return '(Anonymous)'; } return name[1]; }; if (!this.php_js || !this.php_js.resourceData || !this.php_js.resourceDataPointer || !handle || !handle.constructor || getFuncName(handle.constructor) !== 'PHPJS_Resource') { return false; } return this.php_js.resourceDataPointer[handle.id] * 2 - 1; // We're currently storing by character, so need to multiply by two; subtract one to appear like array pointer } {% endcodeblock %} - [view on github](https://github.com/kvz/phpjs/blob/master/functions/filesystem/ftell.js) - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/filesystem/ftell.js) ### Example 1 This code {% codeblock lang:js example %} var h = fopen('http://kevin.vanzonneveld.net/pj_test_supportfile_1.htm', 'r'); fread(h, 100); ftell(h); {% endcodeblock %} Should return {% codeblock lang:js returns %} 99 {% endcodeblock %} ### Other PHP functions in the filesystem extension {% render_partial _includes/custom/filesystem.html %}