Skip to content

Instantly share code, notes, and snippets.

@chardcastle
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chardcastle/6fb037559e3cc90e0028 to your computer and use it in GitHub Desktop.
Save chardcastle/6fb037559e3cc90e0028 to your computer and use it in GitHub Desktop.
Simple PHP checksum (legacy fix)
<?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