note 120210 added to ziparchive.setarchivecomment

From: Date: Tue, 22 Nov 2016 19:25:54 +0000
Subject: note 120210 added to ziparchive.setarchivecomment
Groups: php.notes 
Request: Send a blank email to php-notes+get-207517@lists.php.net to get a copy of this message
Zip archives are encoded in ISO-8859-1 when stored but comments seem to be added in UTF-8 everytime. So... <?php $zip->setArchiveComment("Peña"); //outputs "Peña" as the comment. $zip->setArchiveComment("Peña"); //outputs "NULL" as the comment / no comment is displayed. ?> Using mb_internal_encoding() or mb_http_output() wont change this behavior. At the end you can fix your corrupted comment using something like str_replace(); Consider this: <?php $zip = new ZipArchive; $res = $zip->open('test.zip', ZipArchive::CREATE); if ($res === TRUE) { $zip->addFromString('test.txt', 'file content goes here'); $zip->setArchiveComment('Peña'); //outputs "Peña" as the comment. $zip->close(); $file = file_get_contents('test.zip'); file_put_contents('test.zip', str_replace("Peña", utf8_decode("Peña"), $file)); //outputs "Peña" as the comment. FIXED! echo 'ok'; } else { echo 'failed'; } ?> ---- Server IP: 72.52.91.14 Probable Submitter: 187.226.252.4 ---- Manual Page -- http://php.net/manual/en/ziparchive.setarchivecomment.php Edit -- https://master.php.net/note/edit/120210 Del: integrated -- https://master.php.net/note/delete/120210/integrated Del: useless -- https://master.php.net/note/delete/120210/useless Del: bad code -- https://master.php.net/note/delete/120210/bad+code Del: spam -- https://master.php.net/note/delete/120210/spam Del: non-english -- https://master.php.net/note/delete/120210/non-english Del: in docs -- https://master.php.net/note/delete/120210/in+docs Del: other reasons-- https://master.php.net/note/delete/120210 Reject -- https://master.php.net/note/reject/120210 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#207517) next »