phpjs
Version:
53 lines (43 loc) • 1.58 kB
Markdown
layout: page
title: "JavaScript fscanf function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/fscanf:885
- /functions/view/fscanf
- /functions/view/885
- /functions/fscanf:885
- /functions/885
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's fscanf
{% codeblock filesystem/fscanf.js lang:js https://raw.github.com/kvz/phpjs/master/functions/filesystem/fscanf.js raw on github %}
function fscanf (handle, format) {
// http://kevin.vanzonneveld.net
// + 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;
}
{% endcodeblock %}
- [view on github](https://github.com/kvz/phpjs/blob/master/functions/filesystem/fscanf.js)
- [edit on github](https://github.com/kvz/phpjs/edit/master/functions/filesystem/fscanf.js)
### Example 1
This code
{% codeblock lang:js example %}
var handle = fopen('http://example.com/names_and_professions.html', 'r');
fscanf(handle, '%s\t%s\t%s\n');
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
['robert', 'slacker', 'us']
{% endcodeblock %}
### Other PHP functions in the filesystem extension
{% render_partial _includes/custom/filesystem.html %}