인코딩 변환 채택완료
쿠로네코1
3년 전
조회 1,541
아래는 c#으로 파일 인코딩을 utf-8로 바꿔주는 역할을 합니다.
이걸 php으로 변환 가능 할 까요?
c# 이 윈도우 밖에 지원 안되서 어려움을 겪고 있습니다.
</p>
<p>// Decompiled with JetBrains decompiler
// Type: EncodingChanger.Program
// Assembly: EncodingChanger, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 96F72022-65C4-45AF-9226-92B80F08EF02
// Assembly location: D:\MDweb\apache\web\EncodingChanger.exe</p>
<p>using System.Diagnostics;
using System.IO;
using System.Text;
using System.Web;</p>
<p>namespace EncodingChanger
{
internal class Program
{
private static void Main(string[] args)
{
string str = HttpUtility.UrlDecode(args[0]);
if (Program.GetEncoding(str) != Encoding.UTF8 && Program.GetEncoding(str) != Encoding.ASCII)
Program.SaveToUTF_8(str);
Process.GetCurrentProcess().Kill();
}</p>
<p> public static void SaveToUTF_8(string textFilePath)
{
using (StreamReader streamReader = new StreamReader(textFilePath, Program.GetEncoding(textFilePath), true))
{
using (StreamWriter streamWriter = new StreamWriter(textFilePath + "temp", false, (Encoding) new UTF8Encoding(false)))
{
streamWriter.Write(streamReader.ReadToEnd());
streamWriter.Close();
streamWriter.Dispose();
}
streamReader.Close();
}
File.Delete(textFilePath);
File.Move(textFilePath + "temp", textFilePath);
}</p>
<p> private static Encoding GetEncoding(string filename)
{
using (StreamReader streamReader = new StreamReader(filename, Encoding.Default, true))
{
if (streamReader.Peek() >= 0)
streamReader.Read();
return streamReader.CurrentEncoding;
}
}
}
}
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
답변을 작성하려면 로그인이 필요합니다.
로그인