Skip to content
Snippets Groups Projects
Commit 0a6e9e00 authored by pedro_morgan's avatar pedro_morgan
Browse files

ini_parser class now php5

parent 1d751b04
No related branches found
No related tags found
No related merge requests found
<?php <?php
/**
* ini parser
*
* @author Till Brehm
* @copyright 2005, Till Brehm, projektfarm Gmbh
* @version 0.1
* @package ISPConfig
*/
/* /*
Copyright (c) 2006, Till Brehm, projektfarm Gmbh Copyright (c) 2006, Till Brehm, projektfarm Gmbh
...@@ -28,18 +36,16 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, ...@@ -28,18 +36,16 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
class ini_parser { class ini_parser{
var $config; private $config;
function parse_ini_string($ini) { public function parse_ini_string($ini) {
$ini = str_replace("\r\n","\n",$ini); $ini = str_replace("\r\n", "\n", $ini);
$lines = explode("\n",$ini); $lines = explode("\n", $ini);
foreach($lines as $line) { foreach($lines as $line) {
$line = trim($line);
if($line != '') { if($line != '') {
$line = trim($line);
if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) { if(preg_match("/^\[([\w\d_]+)\]$/", $line, $matches)) {
$section = strtolower($matches[1]); $section = strtolower($matches[1]);
} elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) { } elseif(preg_match("/^([\w\d_]+)=(.*)$/", $line, $matches) && $section != null) {
...@@ -53,12 +59,14 @@ class ini_parser { ...@@ -53,12 +59,14 @@ class ini_parser {
function get_ini_string($file) { public function get_ini_string($file) {
$content = ''; $content = '';
foreach($this->config as $section => $data) { foreach($this->config as $section => $data) {
$content .= "[$section]\n"; $content .= "[$section]\n";
foreach($data as $item => $value) { foreach($data as $item => $value) {
if($value != '') $content .= "$item=$value\n"; if($value != ''){
$content .= "$item=$value\n";
}
} }
} }
return $content; return $content;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment