UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

56 lines (42 loc) 1.8 kB
<!-- Generated by Rakefile:build --> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2009-09-04 18:42:52 <br /> @ fearphage: I like it :) http://github.com/kvz/phpjs/commit/51ac74a14bb0237b202a4a19dc455f45e92da1d5 <hr /> <strong> <a href="http:/my.opera.com/fearphage/" rel="nofollow">fearphage</a> </strong> on 2009-08-30 06:45:27 <br /> <pre><code>function ip2long(ip_address) { var parts = ip_address.match(/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/); return parts ? parts[1] * 16777216 + parts[2] * 65536 + parts[3] * 256 + parts[4] * 1 : false; }</code></pre> <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2009-01-07 13:36:57 <br /> @ Victor: That being said: I did take your idea for using fixed numbers, as I don't see any reason why not to, and it will greatly improve the speed of this function. Thx! <hr /> <strong> <a href="http://kevin.vanzonneveld.net" rel="nofollow">Kevin van Zonneveld</a> </strong> on 2009-01-07 13:29:45 <br /> @ Victor: For minified versions we have php.min.js &amp;amp; in the near future our compiler will be able to compress a custom, smaller selection of functions for more speed &amp;amp; less size. For the original source however, we like to keep things as readable as possible. More info: http://trac.plutonia.nl/projects/phpjs/wiki/DeveloperGuidelines#Comments Thanks a lot for contributing though! <hr /> <strong> Victor </strong> on 2009-01-07 01:44:55 <br /> A minimized version: <pre><code> function ip2long(a){if(a.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)){var b=a.split('.');return(b[0]*16777216)+(b[1]*65536)+(b[2]*256)+(b[3]*1)}else{return&amp;quot;WTF? 0!&amp;quot;}} </code></pre> <hr />