How can I parse a Java proberty file with PHP? -
oi have java proberties file looks more or less this:
fd6aea14b3581255c5d40451cdff8168.hash=90ad759ff0b41abd7260ef1044e75330 fd6aea14b3581255c5d40451cdff8168.path=volumes/ua08154711/08154711/lorem ipsum dolor sit amet, consetetur sadipscing/lorem ipsum dolor sit amet, consetetur sadipscing/07 - lorem ipsum dolor sit amet, consetetur sadipscing - lorem ipsum dolor sit amet, consetetur sadipscing (album version).mp3 ea3f9134319e314bc85d59d16122800.filename=04 - lorem ipsum dolor sit amet, consetetur sadipscing (album version).mp3 ea3f9134319e314bc85d59d16122800.hash=88302129514633aaed4553f1b0ccb6b8 ea3f9134319e314bc85d59d16122800.path=volumes/ua08154711/08154711/lorem ipsum dolor sit amet, consetetur sadipscing/lorem ipsum dolor sit amet, consetetur sadipscing/04 - lorem ipsum dolor sit amet, consetetur sadipscing (album version).mp3 eafb12ee4094d48a2b1bd367e5737c80.filename=._02 - lorem ipsum dolor sit amet, consetetur sadipscing (explicit version).mp3 eafb12ee4094d48a2b1bd367e5737c80.hash=34fb1d1e3523334a89d03de707c00968 eafb12ee4094d48a2b1bd367e5737c80.path=volumes/ua08154711/08154711/lorem ipsum dolor sit amet, consetetur sadipscing/lorem ipsum dolor sit amet, consetetur sadipscing/._02 - lorem ipsum dolor sit amet, consetetur sadipscing (explicit version).mp3 filesize=1024595340 number=03173729
the files destination files/03173729.meta
i want parse file php can save data in mysql database. code:
$filepath = "files/03173729.meta"; $filecontents = file_get_contents("$filepath"); echo $filecontents; $result = parse_properties($filecontents); //fetch contents result array , add them database function parse_properties($txtproperties) { $result = array(); $lines = split("\n", $txtproperties); $key = ""; $iswaitingotherline = false; foreach ($lines $i => $line) { if (empty($line) || (!$iswaitingotherline && strpos($line, "#") === 0)) continue; if (!$iswaitingotherline) { $key = substr($line, 0, strpos($line, '=')); $value = substr($line, strpos($line, '=')+1, strlen($line)); } else { $value .= $line; } /* check if ends single '\' */ if (strrpos($value, "\\") === strlen($value)-strlen("\\")) { $value = substr($value,0,strlen($value)-1)."\n"; $iswaitingotherline = true; } else { $iswaitingotherline = false; } $result[$key] = $value; unset($lines[$i]); } return $result; }
but not know how implement file path code.
you can this:
<?php $filepath = "[your path]"; $filecontents = file_get_contents("$filepath"); $result = parse_preperties($filecontents); //fetch contents result array , add them database function parse_properties($txtproperties) { ... ... ... } ?>
Comments
Post a Comment