Is there a PHP library for parsing POST POSTEST POST files?

if not in PHP, it is possible to use some command line tools that convert a PO file into some structured format, for example. XML or any other that I can simple in PHP?

+6
source share
2 answers

Some simple regular expressions let you parse .PO / .POT files. I recently did similar. Take the following regex from a script I recently wrote:

$poMsgIdAndMsgStrRegex = '/^#\s*(.+?)\nmsgid "(.+?)"\nmsgstr "(.+?)"/m'; 

This only captures the final comment line, but so far is suitable for my purposes. You may need to adapt it.

In any case, you can use the above expression with preg_match_all() to capture all the lines of MsgId and MsgStr into an array of matches. When you have an array, you can put it in any format you want.

There may be libraries for this, but I have not seen them.

Edit: You can also check the PHP class for the .mo file format convertting.po, which is mentioned in the comment "possible duplicate". It doesn't seem like it will solve your problem (since you want to convert .po files to XML), but it's still worth exploring. It helped me a lot.

+1
source

Source: https://habr.com/ru/post/903390/


All Articles