2013-07-01 26 views
0
if(!empty($_FILES['csv'])){ 
     $this->autoRender = false; 
     $text = file_get_contents($_FILES['csv']['tmp_name']); 
     header('Content-type: application/CSV'); 
     header('Content-Disposition: attachment;filename=' . $_FILES['csv']['name']); 
     echo $text; 
     return; 
} 

我沒有問題,上傳文件,然後再出來,你可以在上面看到隨地吐痰回來......但我需要特殊字符轉換像重音字符和EM - 進入等效或HTML版本。我該怎麼做?PHP:上傳CSV和轉換特殊字符爲HTML

Windows 7中的Apache 2.2.21,PHP 5.4.3,CakePHP的1.3

+0

最終使用此(有點髒)功能發現在http://alanwhipple.com/2011/06/04/php-clean-encoding-issues-smart-curly-quotes-em-dashs/ – azBrian

回答

1

看看功能htmlentities()

據我所知,你可能只是你的echo輸出變爲

echo htmlentities($text); 

不要忘了看看可用的標誌in the manual,它允許一些微調取決於你想要什麼。

+0

沒有幫助, htmlentities不會轉換emdash或重音字符... – azBrian

0

您可以使用PHP的htmlentities功能:

$text = htmlentities(file_get_contents($_FILES['csv']['tmp_name'])); 

爲了扭轉這一點,如果你在任何時候需要,使用html_entity_decode

+0

沒有幫助,htmlentities不會轉換emdash或重音字符... – azBrian