We've got some stupid and unrecompilable client code which sends a string to a webservice. The format of the string is created using this code in C#
string strAscii = "";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding ( );
byte[] arrOrg = encoding.GetBytes ( strOrg );
for ( int i = 0; i < arrOrg.Length; i++ )
{
strAscii += arrOrg[ i ].ToString ( "x2" );
}
return strAscii;
This has got to be unravelled by a PHP page. The only way I've managed to get this to work is by converting each couplet of the string to a byte value and putting them into an array.
And then by running this monstrosity:
$arrBytes = array( 0xc3, 0xa9); // this is a single UTF-8 character (e acute)
$fh = fopen("./temp.tmp", "w+");
for($i = 0; $i < count($arrBytes); $i++)
{
fprintf($fh, "%c", $arrBytes[$i]);
}
fclose($fh);
$str = file_get_contents("./temp.tmp");
echo $str;
This works, but it's ridiculous.
Is there any better way of doing it? I've tried all the "standard" type ways, mb_convert_encoding, iconv and pack but to no avail.