UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

60 lines (52 loc) 1.75 kB
--- layout: page title: "JavaScript rewind function" comments: true sharing: true footer: true alias: - /functions/view/rewind:811 - /functions/view/rewind - /functions/view/811 - /functions/rewind:811 - /functions/811 --- <!-- Generated by Rakefile:build --> A JavaScript equivalent of PHP's rewind {% codeblock filesystem/rewind.js lang:js https://raw.github.com/kvz/phpjs/master/functions/filesystem/rewind.js raw on github %} function rewind (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: rewind(h); // * returns 1: true 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; } this.php_js.resourceDataPointer[handle.id] = 0; return true; } {% endcodeblock %} - [view on github](https://github.com/kvz/phpjs/blob/master/functions/filesystem/rewind.js) - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/filesystem/rewind.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); rewind(h); {% endcodeblock %} Should return {% codeblock lang:js returns %} true {% endcodeblock %} ### Other PHP functions in the filesystem extension {% render_partial _includes/custom/filesystem.html %}