awatson Posted September 19, 2008 Share Posted September 19, 2008 I'm just starting to learn PHP and need to convert a section of code from one of my standalone Windows applications to the equivalent functionality in PHP. In my standalone app, I allocate a memory buffer (about 64 bytes) then save and manipulate data in that buffer. For example, I might save a Long integer (4 bytes) to one location and a Short integer (2 bytes) to another location. Then read the buffer contents later byte by byte. But, I don't see any equivalent to allocating a memory buffer in PHP? I thought about using a string to hold the data, but can't figure out how to convert a Long integer into a four-byte string, or a short integer into a two byte string? I also need to ensure the integer is saved in the correct order (big-endian or little-endian, as needed) regardless of which server it is run on. Any tips would be appreciated. Thanks, Anthony Quote Link to comment Share on other sites More sharing options...
DyslexicDog Posted September 19, 2008 Share Posted September 19, 2008 PHP != C, php does all it's own memory handling I don't think a malloc() exists as a PHP subroutine. Quote Link to comment Share on other sites More sharing options...
burn1337 Posted September 19, 2008 Share Posted September 19, 2008 I haven't messed around with php that far yet, but I believe there is something that might help you. Go to php.net research it, I know I once saw something about that stuff, but I was looking for other things so I didn't pay much attention to it. Quote Link to comment Share on other sites More sharing options...
awatson Posted September 19, 2008 Author Share Posted September 19, 2008 My original Windows app is actually written in PowerBASIC, but no matter, I think I figured out how to use a PHP string for the task. The pack() command lets me create the two-byte and four-byte strings as needed with the proper format (little-endian). Simple joining of the individual strings works fine. On to the next step in the code... Thanks, Anthony Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 19, 2008 Share Posted September 19, 2008 /sigh.. You C programmers! If I read any php with a null terminated character array instead of a string, I'm coming for you! Oh PowerBASIC? nevermind ! PHP can cast pretty much anything into anything automatically, even if it doesn't make sense (array->string even works... even if it's just a string filled with the word array). You don't need to worry about memory management or casting for 99% of tasks in PHP... not that it's always a good thing. $str1 = "234alfknel#%FE"; $str2 = "6321alnl3#^"; echo $str1 % $str2; ^php will even try do this without even considering that it makes no friggen sense. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.