'How to edit content in a .phar file?
In my case, the phar file is used to translate an internet page in another language
I have to update a translation, for example:
'Open a New Ticket' => 'old_phrase'
to
'Open a New Ticket' => 'new_phrase'
If I do so by editing the file with a text editor the file is no longer recognized by the system, so I guess I have to use the php Phar class, but I don't know if there's a function to change an existing file in the phar.
Any suggestions / solutions ?
Solution 1:[1]
Use Phar::offsetSet() to change the data of a phar, if you already have the Phar object:
$phar = new Phar("phar.phar");
$phar["entry.php"] .= 'echo "Modified!\n";'
Or use file_put_contents() with the phar scheme:
file_put_contents("phar:///path/to/phar.phar/entry.php", 'echo "Modified!\n";', FILE_APPEND);
Solution 2:[2]
Easy: (https://phar.scer.io/)
-Convert phar to zip.
-Extract and edit.
-Zip and convert zip to phar.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SOFe |
| Solution 2 | Guilherme Reis |
