Last active
August 29, 2015 14:09
-
-
Save chardcastle/6fb037559e3cc90e0028 to your computer and use it in GitHub Desktop.
Simple PHP checksum (legacy fix)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Interesting legacy fix | |
// | |
// This works by replacing a collection of 10 blank spaces with a random character. | |
// However the \e modifier is deprecaited now, it needed replacing as it's hard to | |
// underststand without some notes. | |
// | |
// This line appears to come from http://php.net/manual/en/function.rand.php#86465 | |
// | |
// $f->checksum = preg_replace('/([ ])/e', 'chr(rand(97,122))', ' '); | |
// The purpose of this line can be described as: | |
// Take the first 10 characters from a string of radmonised characters from the alphabet | |
// | |
// This can be expressed in a more graceful (and supported way) as follows | |
$f->checksum = substr(str_shuffle(implode('', range('a', 'z'))), 0, 10); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment