phpjs
Version:
56 lines (45 loc) • 1.67 kB
Markdown
layout: page
title: "JavaScript long2ip function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/long2ip:466
- /functions/view/long2ip
- /functions/view/466
- /functions/long2ip:466
- /functions/466
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's long2ip
{% codeblock network/long2ip.js lang:js https://raw.github.com/kvz/phpjs/master/functions/network/long2ip.js raw on github %}
function long2ip (ip) {
// From: http://phpjs.org/functions
// + original by: Waldo Malqui Silva
// * example 1: long2ip( 3221234342 );
// * returns 1: '192.0.34.166'
if (!isFinite(ip))
return false;
return [ip >>> 24, ip >>> 16 & 0xFF, ip >>> 8 & 0xFF, ip & 0xFF].join('.');
}
{% endcodeblock %}
- [Raw function on GitHub](https://github.com/kvz/phpjs/blob/master/functions/network/long2ip.js)
Please note that php.js uses JavaScript objects as substitutes for PHP arrays, they are
the closest match to this hashtable-like data structure.
Please also note that php.js offers community built functions and goes by the
[McDonald's Theory](https://medium.com/what-i-learned-building/9216e1c9da7d). We'll put online
functions that are far from perfect, in the hopes to spark better contributions.
Do you have one? Then please just:
- [Edit on GitHub](https://github.com/kvz/phpjs/edit/master/functions/network/long2ip.js)
### Example 1
This code
{% codeblock lang:js example %}
long2ip( 3221234342 );
{% endcodeblock %}
Should return
{% codeblock lang:js returns %}
'192.0.34.166'
{% endcodeblock %}
### Other PHP functions in the network extension
{% render_partial _includes/custom/network.html %}