Is there any function or possible way you could do the equivilent of this: explode('',$array) Code (markup): ?
Please be clear when you ask your question Do u know what explode do? $pizza = "piece1 piece2 piece3 piece4 piece5 piece6"; $pieces = explode(" ", $pizza); echo $pieces[0]; // piece1 echo $pieces[1]; // piece2 This pizza is a String not array and pieces is array. Please tell us the content of string which you want to convert into array Regards Alex
It doesn't matter. Like lets say textfile.txt 123456 Code (markup): phpfile.php $file = file_get_contents('textfile.txt'); $array = explode('',$file); Code (markup): So it would be like this $array[0] = 1 $array[1] = 2 $array[2] = 3 ... Do you get what I am trying to do?
Actually if it's a string you can already do this: $string[0] etc.. Without converting to an array. Ofcourse, foreach probably wouldn't work. Well, I don't know, haven't tried.
Hmm I added it to my script now I get a 500 Internal Server Error haha. Anyway want to help? <? function Mid($str,$start,$length) { $array = $str; $number = $start; while($length > $number) { $return .= $array[$number]; $number++; } return $return; } function CLng($str) { $array = explode('.',$str); return $array[0]; } function Decompress($DecompData) { if (strlen($DecompData) > 4) { $ControlCount = ord(substr($DecompData,0,1)) *16777216 + ord(Mid($DecompData, 2, 1)) *65536 + ord(Mid($DecompData, 3, 1)) *256 + ord(Mid($DecompData, 4, 1)); $DataCount = ord(Mid($DecompData, 5, 1)) *16777216 + ord(Mid($DecompData, 6, 1)) *65536 + ord(Mid($DecompData, 7, 1)) *256 + ord(Mid($DecompData, 8, 1)) + 9; $Decompress = Mid($DecompData, $DataCount, 4); $DataCount = $DataCount + 4; $ControlBitPos = 0; $ControlPos = 9; } else { } $DataPost = 1; while($DataPos < $ControlCount) { if(pow(2, $ControlBitPos) == (ord(substr($DecompData, $ControlPos, 1))) && pow(2, $ControlBitPos)) { $DecompStart = strlen($Decompress) - (CLng(ord(Mid($DecompData, $DataCount, 1))) *256 + CLng(ord(Mid($DecompData, $DataCount + 1, 1)))) + 1; $DecompLen = ord(Mid($DecompData, $DataCount + 2, 1)); $Decompress = $Decompress & Mid($Decompress, $DecompStart, $DecompLen); $DataCount = $DataCount + 3; } else { $Decompress = $Decompress . Mid($DecompData, $DataCount, 1); $DataCount++; } $ControlBitPos++; if($ControlBitPos = 8) { $ControlBitPos = 0; $ControlPos++; } else { $Decompress = $DecompData; } $DataPos++; } echo $DecompData; } $FileName = 'test.bin'; $FName = $FileName; $string56 = array_merge(range('0', '9') , range('a' , 'z')); $string56 = array_merge($string56 , range('A' , 'Z')); $zero = '0'; while($zero < 6) { $full .= $string56[rand('0' , count($string56))]; $zero++; } $data = file_get_contents($FileName); $return = Decompress($data); $file = fopen($full . '.jpg','w'); fwrite($file,$return); fclose($file); echo $return . '<br /><br />'; echo $full . '.jpg'; ?> Code (markup):
Well, you'll want to do strlen on the string instead of count, for one. $zero = 0; instead of $zero = '0'; On first sight.
That's not it. I had that there before with no problems. It is with the new part I added at the top. function Mid()
Add: error_reporting(E_ALL); ini_set('display_errors', 1); PHP: at the top of the file.. If it still doesn't show output, you'll have to look into the apache or php error logs.
Okay I put it in then I got this: Notice: Undefined variable: full in /home/nintendo/public_html/brawl/brawl.php on line 82 Notice: Undefined offset: 62 in /home/nintendo/public_html/brawl/brawl.php on line 82 Notice: Undefined variable: return in /home/nintendo/public_html/brawl/brawl.php on line 14 The last one repeats endlessly. I am not sure what the second one means but all of those variables are defined so I don't know what it is talking about.
Sorry to jump in late - I know you can reference a character in a string like premiumscripts said; the function to convert a string to an array is 'str_split'.. $str = "Hello Friend"; $arr1 = str_split($str); print_r($arr1); Array ( [0] => H [1] => e [2] => l [3] => l [4] => o [5] => [6] => F [7] => r [8] => i [9] => e [10] => n [11] => d )
Hmm still getting a 500 error. <? function Mid($str,$start,$length) { $array = str_split($str); $number = $start; while($length > $number) { $return = $return . $array[$number]; $number++; } echo $return; } function CLng($str) { $array = explode('.',$str); return $array[0]; } function Decompress($DecompData) { if (strlen($DecompData) > 4) { $ControlCount = ord(substr($DecompData,0,1)) *16777216 + ord(Mid($DecompData, 2, 1)) *65536 + ord(Mid($DecompData, 3, 1)) *256 + ord(Mid($DecompData, 4, 1)); $DataCount = ord(Mid($DecompData, 5, 1)) *16777216 + ord(Mid($DecompData, 6, 1)) *65536 + ord(Mid($DecompData, 7, 1)) *256 + ord(Mid($DecompData, 8, 1)) + 9; $Decompress = Mid($DecompData, $DataCount, 4); $DataCount = $DataCount + 4; $ControlBitPos = 0; $ControlPos = 9; } else { } $DataPost = 1; while($DataPost < $ControlCount) { if(pow(2, $ControlBitPos) == (ord(substr($DecompData, $ControlPos, 1))) && pow(2, $ControlBitPos)) { $DecompStart = strlen($Decompress) - (CLng(ord(Mid($DecompData, $DataCount, 1))) *256 + CLng(ord(Mid($DecompData, $DataCount + 1, 1)))) + 1; $DecompLen = ord(Mid($DecompData, $DataCount + 2, 1)); $Decompress = $Decompress & Mid($Decompress, $DecompStart, $DecompLen); $DataCount = $DataCount + 3; } else { $Decompress = $Decompress . Mid($DecompData, $DataCount, 1); $DataCount++; } $ControlBitPos++; if($ControlBitPos = 8) { $ControlBitPos = 0; $ControlPos++; } else { $Decompress = $DecompData; } $DataPost++; } echo $DecompData; } $FileName = 'test.bin'; $FName = $FileName; $string = array_merge(range('0', '9') , range('a' , 'z')); $string = array_merge($string , range('A' , 'Z')); $zero = '0'; while($zero < 6) { $full = $full . $string[rand('0' , count($string))]; $zero++; } $data = file_get_contents($FileName); $return = Decompress($data); $file = fopen($full . '.jpg','w'); fwrite($file,$return); fclose($file); echo $return . '<br /><br />'; echo $full . '.jpg'; ?> Code (markup):
Um, you might be best not using return as a variable name. Whilst I'm sure it's fine, it makes the code kinda confusing to read. Saying that, try setting $full = ''; and $return = ''; before you get into the while loop. That should get rid of the undefined variables. I'd hazard a guess the other error on line 62 is because you're trying to access a random array value in $string from 0 to count($string). Arrays are indexed from zero, and your count is the total count starting at 1. So the random number may be: 0,1,2,3,4,5 (or whatever) and the array count is 6 (or whatever), so you're getting the error when the random value is hitting [6].. Any help?
I fixed all of those problems however I still get the 500 error. Thanks for trying to help though I really appreciate it.