user7031185
user7031185

Reputation: 71

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 ?

Upvotes: 5

Views: 5122

Answers (2)

Guilherme Reis
Guilherme Reis

Reputation: 57

Easy: (https://phar.scer.io/)

-Convert phar to zip.

-Extract and edit.

-Zip and convert zip to phar.

Upvotes: 3

SOFe
SOFe

Reputation: 8214

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);

Upvotes: 4

Related Questions