2013年4月12日金曜日

PHPとVB.NETでデータを加工してやり取りする

生データが嫌だけどお手軽にやりたいならビット反転して送るとか。

PHP側
$filename = "hoge.txt";
if ($handle = fopen($filename, "r")) {
  while (!feof($handle)) {
    $s = fread($handle, 1024);
    echo ~$s;
  }
}
fclose($handle);

VB.NET側
Dim filename As String = "hoge.txt";
Dim contents As String = "";
Dim bs(1024 - 1) As Byte
Dim readSize As Integer
Dim fs As New System.IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read)

While True
  readSize = fs.Read(bs, 0, bs.Length)
  If readSize = 0 Then
    Exit While
  End If
  For i As Integer = 0 To bs.Length
    bs(i) = Not bs(i)
  Next
  contents += System.Text.Encoding.UTF8.GetString(bs)
End While
fs.Close()

0 件のコメント:

コメントを投稿