note 30517 deleted from function.explode by bjori
| From: | bjori@php.net | Date: | Mon, 25 Sep 2006 08:14:04 +0000 |
| Subject: | note 30517 deleted from function.explode by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-117610@lists.php.net to get a copy of this message | ||
Note Submitter: johnnycobol at yahoo dot com
----
If you need to parse Java properties using PHP, here is an example I wrote:
<?php
//Takes a multi-line string as input. Returns an array
//which can be accessed by property name.
function propertiesToArray($propertiesList)
{
$properties = explode("\n", trim($propertiesList));
$propArray = array();
foreach ($properties as $nameValue)
{
list($propName, $propValue) = explode("=", $nameValue);
$propArray[$propName] = $propValue;
}
return $propArray;
}
$testprop = "property1=value1\nproperty2=value2\n\rproperty3=\n"
. "property4=value4";
$props = propertiesToArray($testprop);
foreach ($props as $key => $value)
{
echo "$key => $value<br>\n";
}
?>