im trying to display a string with php but what I want is to add letters to all the blank spaces in the sentence in alphabetical order.
Example:
string:
Hello world this is a test
new string:
Helloaworldbthiscisdaetest
so all the way to z. and if the string has more spaces than in the alphabet then I want to start back to a then to z
what I have so far
<?php
function do_offset($level){
$offset = ""; // offset for subarry
for ($i=1; $i<$level;$i++){
$offset = $offset . "<td></td>";
}
return $offset;
}
function show_array($array, $level, $sub){
$getit = 0;
if (is_array($array) == 1){ // check if input is an array
foreach($array as $key_val => $value) {
$getit = $getit + 1;
$offset = "";
if (is_array($value) == 1){ // array is multidimensional
echo "<tr>";
$offset = do_offset($level);
echo $offset . "<td>" . $key_val . "</td>";
show_array($value, $level+1, 1);
}
else{ // (sub)array is not multidim
if ($sub != 1){ // first entry for subarray
//echo "<tr>";
$offset = do_offset($level);
}
$sub = 0;
if ($getit > 40) {
if ($value == " ") {
echo $offset . "<td width=\"120\" align=\"center\" onDblClick=\"style.backgroundColor='#000000';\">".strtolower(genstring(1))."</td></tr>\n";
} else {
echo $offset . "<td width=\"120\" align=\"center\" onDblClick=\"style.backgroundColor='#000000';\">".strtolower($value)."</td></tr>\n";
}
$getit = 0;
} else {
if ($value == " ") {
echo $offset . "<td width=\"120\" align=\"center\" onDblClick=\"style.backgroundColor='#000000';\">".strtolower(genstring(1))."</td>\n";
} else {
echo $offset . "<td width=\"120\" align=\"center\" onDblClick=\"style.backgroundColor='#000000';\">".strtolower($value)."</td>\n";
}
}
//echo "</tr>\n";
}
} //foreach $array
}
else{ // argument $array is not an array
return;
}
}
function genstring($length){
srand((double)microtime()*1000000);
$cons = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
$num_cons = count($cons);
for($i = 0; $i < $length; $i++){
//$getnewstr .= $cons[rand(0, $num_cons - 1)];
$getnewstr .= $cons[rand(0, $num_cons - 1)];
}
return substr($getnewstr, 0, $length);
}
function html_show_array($array){
echo "<table cellspacing=\"0\" border=\"0\" width=\"640\" align=\"center\">\n";
echo "<tr>";
show_array($array, 1, 0);
echo "</tr></table>\n";
}
$str = 'Hello world this is a test sentence to check out how this php script works. This is only a test.';
$chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
//print_r($chars);
html_show_array($chars);
?>
code above works but it does put the letters in alphabetical order.
thanks
D