String Scrambler

String Scrambler

The following funtion is used to convert the given string into randomized order

<?php

function String_Scramble($string)

{

$arr1 = array();

$output = ‘’;

$len = strlen($string);

for ($i = 0; $i < $len; $i++)

{

$rand = rand(0, $len);

while (isset($arr1[$rand]))

$rand = rand(0, $len);

$output .= $string[$rand];

$arr1[$rand] = true;

}

return $output;

}

// Example usage

echo String_Scramble(”Sample text”);

?>

In above example, String_Scramble is the funtion which will shuffle input string. In String_Scramble funtion, we can use rand() funtion to fetch random values from input string.

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.