note 117335 added to function.str-shuffle
| From: | krzysiekpiasecki at gmail dot com | Date: | Sat, 23 May 2015 09:06:03 +0000 |
| Subject: | note 117335 added to function.str-shuffle | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202646@lists.php.net to get a copy of this message | ||
/**
* Test shuffleString
*/
function testShuffleString() {
$shuffled = shuffleString("ÄÄźÄÃ");
if (\mb_strlen($shuffled) != 5) {
throw new \UnexpectedValueException("Invalid count of characters");
}
if ($shuffled == "ÄÄźÄÃ") {
throw new \UnexpectedValueException("The same string");
}
foreach (["Ä", "Ä", "ź", "Ä",
"Ã"] as $char) {
if (\mb_strpos($shuffled, $char) === false) {
throw new \UnexpectedValueException("Character not found");
}
}
}
/**
* Shuffle string
*
* @param $stringValue String to shuffle
* @param string $startWith Shuffle $stringValue and append to $startWith
* @return string Shuffled string
* @author Krzysztof Piasecki<krzysiekpiasecki@gmail.com>
*/
function shuffleString($stringValue, $startWith = "") {
$range = \range(0, \mb_strlen($stringValue));
shuffle($range);
foreach($range as $index) {
$startWith .= \mb_substr($stringValue, $index, 1);
}
return $startWith;
};
testShuffleString();
echo shuffleString("Hello"); // > 'elHol' (something like this)
echo shuffleString("World!", "Hello "); // > 'Hello do!lrW'
(something like this)
----
Server IP: 72.52.91.14
Probable Submitter: 82.143.191.1
----
Manual Page -- http://php.net/manual/en/function.str-shuffle.php
Edit -- https://master.php.net/note/edit/117335
Del: integrated -- https://master.php.net/note/delete/117335/integrated
Del: useless -- https://master.php.net/note/delete/117335/useless
Del: bad code -- https://master.php.net/note/delete/117335/bad+code
Del: spam -- https://master.php.net/note/delete/117335/spam
Del: non-english -- https://master.php.net/note/delete/117335/non-english
Del: in docs -- https://master.php.net/note/delete/117335/in+docs
Del: other reasons-- https://master.php.net/note/delete/117335
Reject -- https://master.php.net/note/reject/117335
Search -- https://master.php.net/manage/user-notes.php