Hi, I think you shouldn't use UTF-8 and mb_ functions. In this scenario, one useful property of the php strings API is that doesn't really "understand" anything about encodings. A byte is a char and that's all, so you can use that API as if it were acting on raw buffers. In this case, that's what you need, because if you parse the data as UTF-8 you are most likely going to get illegal sequences at some point.
I've written a little test and it seems to be working (at least I receive the expected results back in the flash side). Cheers Juan Pablo Califano AS CODE (in the timeline, mind you): import flash.utils.ByteArray; var buffer:ByteArray = new ByteArray(); buffer[0] = 0x43; buffer[1] = 0x61; buffer[2] = 0x6c; buffer[3] = 0x69; buffer[4] = 0x66; buffer[5] = 0x61; buffer[6] = 0x00; buffer.compress(); buffer.position = 0; var dump:String = "$data = "; while(buffer.bytesAvailable > 0) { dump += "chr(0x" + buffer.readUnsignedByte().toString(16) + ")"; if(buffer.bytesAvailable > 0) { dump += " . "; } } dump += ";"; trace("dump from flash: " + dump); import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLRequestMethod; import flash.net.URLLoaderDataFormat; import flash.events.*; function completeHandler(event:Event):void { var loader:URLLoader = URLLoader(event.target); trace("data received from PHP: \n" + loader.data); } var urlLoader:URLLoader = new URLLoader(); urlLoader.dataFormat = URLLoaderDataFormat.BINARY; urlLoader.addEventListener(Event.COMPLETE, completeHandler); var req:URLRequest = new URLRequest("http://localhost/compress/compress.php "); req.method = URLRequestMethod.POST; req.data = buffer; urlLoader.load(req); PHP FILE: <?php //$data = chr(0x78) . chr(0xda) . chr(0x73) . chr(0x4e) . chr(0xcc) . chr(0xc9) . chr(0x64) . chr(0x0) . chr(0x0) . chr(0x4) . chr(0xee) . chr(0x1) . chr(0x7a); $data = file_get_contents("php://input","rb"); $trimmed_data = substr($data, 2); $decoded = gzinflate($trimmed_data); echo dumpToHexString($trimmed_data); echo dumpToHexString($decoded); function dumpToHexString($input) { $ret = ''; $len = strlen($input); $i = 0; while($i < $len) { $ret .= "[$i] : " . dechex(ord($input[$i])) . " \n"; $i++; } return $ret; } ?> 2008/10/3, Benny <[EMAIL PROTECTED]>: > > (please ignore previous reply - contained mistakes regarding gzuncompress > while I meant gzinflate) > > Thanks Juan Pablo Califano. > > I'm already sending the data in binary form so that's is probably not the > problem. > You are right about that the php decompression should be done with > gzinflate > (I did test with it before but that didn't work either so I thought I > should > try gzuncompress ;) > > When I compare the deflating results of the same string in PHP and Flash I > noticed that flash started with two extra bytes while the rest of the > output > was the same. > > Next I added this code to the PHP test script to remove the two extra > leading bytes: > > mb_internal_encoding("UTF-8"); > $encoded = mb_substr($_POST["XMLString"], 2); > > Now when I compare the string in $encoded with the encoded string produced > by PHP deflate() then both seem to be exactly the same. So I expected that > > $decoded = gzinflate($encoded); > > would now return the original string but no, an empty string is returned!? > > If however I copy (i.e. hardcode) the compressed string into $encoded and > then execute > > $decoded = gzinflate($encoded); > > Then it Works; I get the original text!? > > Big question now why does it work with the hardcoded compressed string and > not with runtime compressed string, they seem to be exactly the same?? > > Any ideas? > > BTW: thanks for your time :) > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders