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 += ($hash << 1) + ($hash << 4) + ($hash << 7) + ($hash << 8) + ($hash << 24); $hash = $hash ^ ord($chr); } $hash = $hash & 0x0ffffffff; return $hash; } var_dump(fnvhash_fnv1("test")); var_dump(fnvhash_fnv1("tess"));
Output for 8.1.0 - 8.1.6
Deprecated: Implicit conversion from float 1.809407868354093E+19 to int loses precision in /in/bXN6i on line 46 Deprecated: Implicit conversion from float -1.8602116834384482E+19 to int loses precision in /in/bXN6i on line 46 int(540209268) Deprecated: Implicit conversion from float 1.809407868354093E+19 to int loses precision in /in/bXN6i on line 46 Deprecated: Implicit conversion from float -1.8602116834384482E+19 to int loses precision in /in/bXN6i on line 46 int(540209267)
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.25, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.29, 8.0.0 - 8.0.19
int(540209268) int(540209267)
Output for 5.0.0 - 5.0.1, 5.0.3 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
int(116) int(115)
Output for 5.0.2
int(2348763408) int(2348763415)
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: str_split() in /in/bXN6i on line 41
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: str_split() in /in/bXN6i on line 41
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: str_split() in /in/bXN6i on line 41

preferences:
51.66 ms | 415 KiB | 5 Q