Re: CF equivalent to PHP pack() function
and this isn't a CF equivalent, it's a javascript equivalent. That's not JavaScript, it's Java, which can be run from within a CF page with a bit of effort. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information! ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314754 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF equivalent to PHP pack() function
Hi all! I've found a java equivalent to PHP pack('H*', function Here it is: code String myHexStr = D0A0D0B0D0B7D0BCD0B5D180D18B; //some string in Russian, charset UTF-8 byte [] b = new BigInteger(parNameHex, 16).toByteArray(); //maybe other constructor to implement other formats of pack() String myStr = new String(b, UTF-8).substring(1); //first char is sign /code ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314731 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: CF equivalent to PHP pack() function
So.. This being a CF list... What does PHP pack do? and this isn't a CF equivalent, it's a javascript equivalent. Alexey Passichenko wrote: Hi all! I've found a java equivalent to PHP pack('H*', function Here it is: code String myHexStr = D0A0D0B0D0B7D0BCD0B5D180D18B; //some string in Russian, charset UTF-8 byte [] b = new BigInteger(parNameHex, 16).toByteArray(); //maybe other constructor to implement other formats of pack() String myStr = new String(b, UTF-8).substring(1); //first char is sign /code ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314733 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF equivalent to PHP pack() function
So.. This being a CF list... What does PHP pack do? and this isn't a CF equivalent, it's a javascript equivalent. In PHP Pack() is a complicated way of doing the equivalent of this in CF: toBinary(toBase64(my string)) What's added by pack() beyond that CF example is a bunch of formatting options for the input string like pad-with-spaces, pad-with-nulls, etc. The H option he mentioned is described as Hex string, high nibble first. My guess would be high nibble first vs. low nibble first (lowercase h) is describing unicode formatting - whether it's the high bit or the low bit that indicates if the current byte is the beginning of a double-byte character. I'm not certain of that though. -- s. isaac dealey ^ new epoch isn't it time for a change? ph: 781.769.0723 http://onTap.riaforge.org/blog ~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;207172674;29440083;f Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:314736 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: CF equivalent to PHP pack() function
Thank you for your responses, I'll give Corfield's tag a shot. If that doesn't work, I'll post my attempt at re-writing the Perl example. Thanks again guys. ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289667 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: CF equivalent to PHP pack() function
There's no direct equivalent in CF; there isn't even a direct equivalent in Java (as far as I can see). It seems you'll have to write one - perhaps crack open the source for that function in PHP (or the original form in Perl). On 9/27/07, Daniel Smith [EMAIL PROTECTED] wrote: In PHP there is a function called pack() http://us3.php.net/pack;. The function will pack data into a binary string. I assumed that this would be done using CF's CharsetEncode(), but the result was not as I expected. I am specifically trying to call pack('N',foo), which will encode as unsigned long (always 32 bit, big endian byte order). I have spent the 3hrs looking for an answer and came up dry. Any help would be much appreciated. Thanks. ~| ColdFusion 8 - Build next generation apps today, with easy PDF and Ajax features - download now http://download.macromedia.com/pub/labs/coldfusion/cf8_beta_whatsnew_052907.pdf Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289585 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Re: CF equivalent to PHP pack() function
Sean Corfield (www.corfield.org) has a custom tag that uses a Java-based PHP implementation (can't remember the name) to allow execution of inline PHP code from CF templates. I don't know if they implement the pack() function, but I'd think it likely. If they do, you could use that to get your pack() function in CF, though it's using a wrecking ball to pound in a finishing nail. cheers, barneyb On 9/26/07, James Holmes [EMAIL PROTECTED] wrote: There's no direct equivalent in CF; there isn't even a direct equivalent in Java (as far as I can see). It seems you'll have to write one - perhaps crack open the source for that function in PHP (or the original form in Perl). On 9/27/07, Daniel Smith [EMAIL PROTECTED] wrote: In PHP there is a function called pack() http://us3.php.net/pack;. The function will pack data into a binary string. I assumed that this would be done using CF's CharsetEncode(), but the result was not as I expected. I am specifically trying to call pack('N',foo), which will encode as unsigned long (always 32 bit, big endian byte order). I have spent the 3hrs looking for an answer and came up dry. Any help would be much appreciated. Thanks. -- Barney Boisvert [EMAIL PROTECTED] http://www.barneyb.com/ Got Gmail? I have 100 invites. ~| Enterprise web applications, build robust, secure scalable apps today - Try it now ColdFusion Today ColdFusion 8 beta - Build next generation apps Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289586 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Re: CF equivalent to PHP pack() function
Oh, yes, that's possibly a way around it, although as you say it's rather like using nukes to rid yourself of an ant problem. Quercus is the package and I've been playing with it - it's only useful in CF8 as it depends on Java 6. On 9/27/07, Barney Boisvert [EMAIL PROTECTED] wrote: Sean Corfield (www.corfield.org) has a custom tag that uses a Java-based PHP implementation (can't remember the name) to allow execution of inline PHP code from CF templates. I don't know if they implement the pack() function, but I'd think it likely. If they do, you could use that to get your pack() function in CF, though it's using a wrecking ball to pound in a finishing nail. -- mxAjax / CFAjax docs and other useful articles: http://www.bifrost.com.au/blog/ ~| Get involved in the latest ColdFusion discussions, product development sharing, and articles on the Adobe Labs wiki. http://labs/adobe.com/wiki/index.php/ColdFusion_8 Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289587 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
RE: CF equivalent to PHP pack() function
I had to simulate pack(L) from perl. I don't know if this will help, but I figured I would share it. /* create_perl_packed_string_L This simulates the command pack (L, $now) function from perl. It converts a number from numerals into the asci character representation of it's 32 bit binary form. */ function create_perl_packed_string_L(number) { // convert number to binary bin_number=formatBaseN(number,2); // Figure out how many 0's make it 32 bit bin_number_length=Len(bin_number); prepend_count=32- bin_number_length; prepend=; for (i=1;i lte prepend_count; i=i+1) { prepend = prepend 0; } // add prefixed 0's bin_number= prepend bin_number; //break into octets octet_array=arrayNew(1); j=1; for (i=1; i lte 32; i=i+8) { octet_array[j]=Mid(bin_number,i,8); j=j+1; } //convert to proper string packed_string=; for (i=1; i lte 4; i=i+1) { packed_string=packed_string Chr(InputBaseN(octet_array[i],2)); } return(packed_string); } Terrence Ryan I.T. Director Wharton Computing and Information Technology E-mail: [EMAIL PROTECTED] ~| Download the latest ColdFusion 8 utilities including Report Builder, plug-ins for Eclipse and Dreamweaver updates. http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:289589 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4