0

Hey i am passing a string to an array and using the str_split.

$string = "Green"; $array = str_split($string,1); print_r($array); ?>

what i want to do is split the string to individual characters but not store the character , i would like to convert each individual character to its respective ascii value. Then add +10 to the ascii value.

1
Contributor
1
Reply
2
Views
4 Years
Discussion Span
Last Post by FakeTales
0

I have solved the issues here is the code , the code is long and i think it is a total hack. i am able to convert the chars to ascii values using ord , then i add +10 to the ascii value.

<?php

$string = "Green";
$array = str_split($string,1);
print_r($array);
reset($array);
?>

</br>
</br>

<?php
$arr = ($array);
reset($arr);

foreach ($arr as $key => $value) {
$arr[$key] = $array[$key]; unset( $array[$key] );
echo "Key: $key; Value: $value<br />\n";


}

?>

</br>
</br>
<h3> Green Converted to Ascii Bits </h3>

<?php
$newarr = ($arr);
reset($newarr);


foreach ($newarr as $key => $value) {
$newarr[$key] = $arr[$key]; unset( $arr[$key] );
 $value = ord($value);
    echo "Key: $key; Ascii: $value<br />\n";

}

?>

</br>
</br>
<h3> Green Converted to Ascii Bits +10 added to value </h3>

<?php
$arry = $newarr;
reset($arry);
$addition = 10; 
$newValue;

foreach ($arry as $key => $value) {
$arry[$key] = $newarr[$key]; unset( $newarr[$key] );
 $value = ord($value);
    $newValue = $value + $addition;
    echo "Key: $key; Ascii: $newValue<br />\n";

    }



?>

Now i just need to access the new array that hold the ascii values with +10 to minus them by -10 to get the original value back , then post these values back into the original chars then put them all back into a string , like i said this seems to be a very long method to do it , is it possible to do this in a couple of lines of code ?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.