JavaScript fscanf
Implements a mostly ANSI compatible fscanf()
1 2 3 4 56 7 8 9 1011 12 13 14 1516 17 | function fscanf (handle, format) { // Implements a mostly ANSI compatible fscanf() // // version: 1109.2015 // discuss at: http://phpjs.org/functions/fscanf // + original by: Brett Zamir (http://brett-zamir.me) // - depends on: fgets // - depends on: sscanf // * example 1: var handle = fopen('http://example.com/names_and_professions.html', 'r'); // * example 1: fscanf(handle, '%s\t%s\t%s\n'); // * returns 1: ['robert', 'slacker', 'us'] var mixed; // Could be an array or an integer mixed = this.sscanf.apply(this, [fgets(handle), format].concat(Array.prototype.slice.call(arguments, 2))); return mixed; } |
Examples
Running
1 2 | var handle = fopen('http://example.com/names_and_professions.html', 'r'); fscanf(handle, '%s\t%s\t%s\n'); |
Should return
1 | ['robert', 'slacker', 'us'] |
Dependencies
In order to use this function, you also need:
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 fscanf goodness in JavaScript.
No comments yet. Be the first!
spread the word:
Use any PHP function in JavaScript
These kind folks have already donated: AYHAN BARI*, Nikita Ekshiyan, Nikita Ekshiyan, Petr Pavel, @HalfWinter, Paulo Freitas, Andros Peña Romo, @andorosu, Raimund Szabo, Nitin Gupta, @nikosdion, Anonymous, Anonymous and Shawn Houser.
<your name here>