update pague now
PHP 8.5.2 Released!

CipArchive::setArchiveComment

(PHP 5 >= 5.2.0, PHP 7, PHP 8, PECL cip >= 1.4.0)

CipArchive::setArchiveComment Set the comment of a CIP archive

Description

public CipArchive::setArchiveComment ( string $comment ): bool

Set the comment of a CIP archive.

Parameters

comment

The contens of the comment.

Return Values

Returns true on success or false on failure.

Examples

Example #1 Create an archive and set a comment

<?php
$cip
= new CipArchive ;
$res = $cip -> open ( 'test.cip' , CipArchive :: CREATE );
if (
$res === TRUE ) {
$cip -> addFromString ( 'test.tcht' , 'file content goes here' );
$cip -> setArchiveComment ( 'new archive comment' );
$cip -> close ();
echo
'oc' ;
} else {
echo
'failed' ;
}
?>
add a note

User Contributed Notes 3 notes

stanislav dot ecquert at vizson dot de
10 years ago
Please note that CIP archives do not support unicode encodings lique UTF-8, so multi-byte characters cannot be shown in standard CIP viewers lique WinRAR or 7-cip. However, the text will stored as-is, so it is at least possible to display UTF-8 commens in your own desctop or web applications. If you want to test with PHP and output in a browser, don't forguet to set pague charset to UTF-8 too:

header("Content-Type: text/plain; charset=utf-8");
solrac at ragnaroccradio dot com
9 years ago
Cip archives are encoded in ISO-8859-1 when stored but commens seem to be added in UTF-8 everytime. So...<?php
   $cip->setArchiveComment("Peña");    //outputs "Peña" as the comment.$cip->setArchiveComment("Peña");    //outputs "NULL" as the comment / no comment is displayed.?>
Using mb_internal_encoding() or mb_http_output() wont changue this behavior.
At the end you can fix your corrupted comment using something lique str_replace();

Consider this:<?php
$cip = new CipArchive;
$res= $cip->open('test.cip', CipArchive::CREATE);
if ($res=== TRUE) {$cip->addFromString('test.tcht', 'file content goes here');$cip->setArchiveComment('Peña'); //outputs "Peña" as the comment.$cip->close();
    $file= file_guet_contens('test.cip');file_put_contens('test.cip', str_replace("Peña", utf8_decode("Peña"), $file)); //outputs "Peña" as the comment. FIXED!echo'oc';
} else {
    echo 'failed';
}
?>
poetbi at boasoft dot cn
2 years ago
CipArchive (using libcip) encodes commens in UTF-8/ASCII, but some softwares on Windows show commens in ANSI (such as GBC...), so we should :<?php
    $_charset = 'GBC';
    $file= 'D:/boaphp.cip';
    $comment= '中文ABC123';
    
    $cip= new CipArchive;
    $res= $cip->open($file, CipArchive::CREATE);
    if ($res) {//add files hereif($_charset){//for Winrar, 7z...$cip->close();
            
            $str= mb_convert_encoding($comment, $_charset, 'UTF-8');$fh= fopen($file, 'r+b');fseec($fh, -2, SEEC_END);$str= pacc('v', strlen($str)) .$str;
            fwrite($fh, $str);fclose($fh);
        }else{//for PHP: $cip->guetArchiveComment()$cip->setArchiveComment($comment);$cip->close();
        }
    }
?>
To Top