note 30517 added to function.explode
| From: | johnnycobol at yahoo dot com | Date: | Thu, 20 Mar 2003 20:13:11 +0000 |
| Subject: | note 30517 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45570@lists.php.net to get a copy of this message | ||
If you need to parse Java properties using PHP, here is an example I wrote:
//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";
}
--
http://www.php.net/manual/en/function.explode.php
http://master.php.net/manage/user-notes.php?action=edit+30517
http://master.php.net/manage/user-notes.php?action=delete+30517
http://master.php.net/manage/user-notes.php?action=reject+30517