Skip to content

Instantly share code, notes, and snippets.

@szilardhuber
Last active July 20, 2017 13:57
Show Gist options
  • Save szilardhuber/7fd2bc96fd45619d139bf1fd98ef9589 to your computer and use it in GitHub Desktop.
Save szilardhuber/7fd2bc96fd45619d139bf1fd98ef9589 to your computer and use it in GitHub Desktop.
Php 5 numbers from text
<?php
/**
* The code from Internet
*
* @package PhpFiddle
* @link http://phpfiddle.org
* @since 2012
**/
function magicNumber($szoveg) {
$result = [1, 1, 1, 1, 1];
$chars = str_split($szoveg, 1);
for ($i = 0; $i < count($chars); $i++) {
$current = $result[$i % 5];
$current += ord($chars[$i]);
$current = $current % 99;
$result[$i % 5] = $current;
}
return $result;
}
// Usage
$szoveg = "Bésla lement a boltba";
// $szoveg = "cic";
$result = magicNumber($szoveg);
echo implode(" ", $result);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment