Created
March 6, 2019 05:25
-
-
Save sagormax/9a18a1636f0193554abaf7707a02d303 to your computer and use it in GitHub Desktop.
Convert headers to Japanese. Here is a process of rewriting from [PATTERN] below to [TO STRING]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$strCsvFilePath = DIR_CSV . $strCsvFileName; // SaveDir | |
$strCsvDownloadUrl = URL_HOST . 'csv/' . $strCsvFileName; // Download Url | |
mb_language("Japanese"); | |
// Header | |
$strCsvFileText = file_get_contents($strCsvFilePath); | |
$from_encoding = CSV_ENCODE_AFTER; | |
foreach (array('UTF-8', 'SJIS', 'EUC-JP', 'ASCII', 'JIS') as $charcode) { | |
if (strcmp(mb_convert_encoding($strCsvFileText, $charcode, $charcode), $strCsvFileText) == 0) { | |
$from_encoding = $charcode; | |
break; | |
} | |
} | |
// TODO: Convert headers to Japanese | |
// TODO: Hint: There is a process of rewriting from [PATTERN] below to [TO STRING]. | |
// TODO: Hint: Please correct it and use it. | |
// TODO: Hint: Add it elsewhere if necessary. | |
$strCsvFileText = mb_convert_encoding($strCsvFileText, "SJIS-win", $from_encoding); | |
$strCsvFileText = mb_ereg_replace("PATTERN", mb_convert_encoding("TO STRING", "SJIS-win", "UTF-8"), $strCsvFileText); | |
file_put_contents($strCsvFilePath, $strCsvFileText); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment