Skip to content

Instantly share code, notes, and snippets.

@gabrielkiss
gabrielkiss / parseProperties.php
Created May 12, 2020 14:09
Parse java .properties files in PHP
function parseProperties($fileContent) {
$result = [];
$fileContent = str_replace("\r\n", "\n", $fileContent);
$lines = explode("\n", $fileContent);
$lastkey = '';
$appendNextLine = false;
foreach ($lines as $l) {
$cleanLine = trim($l);
if ($cleanLine === '') continue;
if (strpos($cleanLine, '#') === 0) continue; // is comment ... move on