note 30517 modified in function.explode by aidan

From: Date: Sun, 27 Jun 2004 14:27:19 +0000
Subject: note 30517 modified in function.explode by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-71925@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: <?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"; } ?> --was-- 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://php.net/manual/en/function.explode.php

« previous php.notes (#71925) next »