3v4l.org

run code in 300+ PHP versions simultaneously
<?php define ("FNV_prime_32", 16777619); define ("FNV_prime_64", 1099511628211); define ("FNV_prime_128", 309485009821345068724781371); define ("FNV_offset_basis_32", 2166136261); define ("FNV_offset_basis_64", 14695981039346656037); define ("FNV_offset_basis_128", 144066263297769815596495629667062367629); /* * The core of the FNV-1 hash algorithm is as follows: * * hash = offset_basis * for each octet_of_data to be hashed * hash = hash * FNV_prime * hash = hash xor octet_of_data * return hash * * Source: http://www.isthe.com/chongo/tech/comp/fnv/ */ /* * Example Java implementation: * * long fnv(byte[] buf, int offset, int len, long seed) * { * for (int i = offset; i < offset + len; i++) * { * seed += (seed << 1) + (seed << 4) + (seed << 7) + (seed << 8) + (seed << 24); * seed ^= buf[i]; * } * return seed; * } * * `Source: http://www.getopt.org/ - FNV1 Hash */ function fnvhash_fnv1($txt) { $buf = str_split($txt); $hash = FNV_offset_basis_32; foreach ($buf as $chr) { $hash = 0x0ffffffff & ($hash * FNV_PRIME_32); $hash ^= ord($chr); } $hash = $hash & 0x0ffffffff; return $hash; } var_dump(fnvhash_fnv1("test")); var_dump(fnvhash_fnv1("tess"));
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Undefined constant "FNV_PRIME_32" in /in/8DdHT:45 Stack trace: #0 /in/8DdHT(53): fnvhash_fnv1('test') #1 {main} thrown in /in/8DdHT on line 45
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
35.63 ms | 401 KiB | 8 Q