CronJob-Service
bei SELFPHP mit ...
|
+ minütlichen Aufrufen
+ eigenem Crontab Eintrag
+ unbegrenzten CronJobs
+ Statistiken
+ Beispielaufrufen
+ Control-Bereich
Führen Sie mit den CronJobs von
SELFPHP zeitgesteuert Programme
auf Ihrem Server
aus. Weitere Infos

|
:: Anbieterverzeichnis ::
Globale Branchen
Informieren Sie sich über ausgewählte Unternehmen im Anbieterverzeichnis von SELFPHP 
:: Newsletter ::
Abonnieren Sie hier den kostenlosen
SELFPHP Newsletter!
|
PHP Grundlagen Hier kann über grundlegende Probleme oder Anfängerschwierigkeiten diskutiert werden |

23.09.2008, 14:36:06
|
Anfänger
|
|
Registriert seit: Sep 2008
Alter: 46
Beiträge: 3
|
|
REG EXPRESSION in .INI schreiben - aber wie?
Grüß Euch alle!
Hiermit mein erster Beitrag im Forum:
Ich schreibe per PHP eine Anwendung welche per WINBINDER eine Benutzeroberfläche erhalten hat und später mal zu einer .exe kompilliert werden soll.
Nun habe ich eine Menge Regular Expressions welche ich in eine .INI schreiben will -
prinzipiell in Array-Form, keine verschachtelten Arrays. Beim Auslesen soll alles in einem multidim. Array gesammelt werden.
Beispiel:
[Letztes]
Folder = "C:/"
Starttext = "<publicinfo>"
Endtext = "</publicinfo>"
Rekursiv = "0"
Letzte_config = ""
[STANDARD]
Folder = "D:/PROG/LSP_SOURCECODE/"
Starttext = "(?=;\|\s{5}_{1,})"
Endtext = "(?<=\s{10}\|;)"
Rekursiv = "0"
in einer Variable als Array funktionieren die RegExp´s - aber wie kann ich diese
1. in eine .ini schreiben (liegt lokal in einem Verzeichnis auf der HD mit Schreibberechtigung)
2. diese wieder auslesen
alle bisher gefundenen Ansätze eine .ini zu erstellen versagen gerade bei den Steuerzeichen - meine Grundidee war diese Suchbegriffe vorher irgendwie zu konvertieren - aber wie?
ich bin auf PHP nicht unbedingt sehr fit - wurschtel mich gerade mal durch, deswegen hier die Bitte um Hilfe in diesem Bereich!
danke im Voraus
Wolfgang S
|

23.09.2008, 16:08:40
|
 |
Administrator
|
|
Registriert seit: Jul 2004
Beiträge: 3.707
|
|
AW: REG EXPRESSION in .INI schreiben - aber wie?
Willkommen im Forum!
Da fallen mir auf anhieb nur die Gebrüder: fopen() / fwrite() / fclose() ein.
__________________
Gruss vt1816
Erwarte nicht, dass sich jemand mehr Mühe mit der Antwort gibt als Du Dir mit der Frage.
. . . . . Feedback wäre wünschenswert
Ich werde keinen privaten 1:1 Support leisten, außer ich biete ihn ausdrücklich an.
Ansosnten gilt: Hilfe ausserhalb dieses Thread (PN, WhatsApp, Skype, Mail, ICQ, etc...) nur per Barzahlung oder Vorauskasse!
Wenn man sich selbst als "Noob" bezeichnet, sollte man die Finger davon lassen.
Wenn man gewillt ist daran etwas zu ändern, lernt man Grundlagen!
|

23.09.2008, 17:30:51
|
Anfänger
|
|
Registriert seit: Sep 2008
Alter: 46
Beiträge: 3
|
|
AW: REG EXPRESSION in .INI schreiben - aber wie?
Hallo vt1816!
Danke für den Tip gleichmal, ich dachte nicht, daß der "normale" Fwrite solche Sonderzeichen weitergibt - ma´ lernt nie aus!
Ich habe selbst von de.php.net eine READ/WRITE-INI Funktion heruntergeladen und modifiziert, deswegen haben sich anscheinend auch die Probleme ergeben.
Die Lösung war´s nun mit ADDCSLASHES alle "\" zusätzlich zu maskieren, die anderen Sonderzeichen hat´s bis jetzt brav weitergegeben.
danke
Wolfgang
|

23.09.2008, 21:16:06
|
 |
Member
|
|
Registriert seit: Jul 2006
Ort: Göttingen/Deutschland
Alter: 36
Beiträge: 586
|
|
AW: REG EXPRESSION in .INI schreiben - aber wie?
Versuche es doch mal mit dieser Klasse. Die habe ich mal geschrieben, um besser mit *.ini-Dateien arbeiten zu können. Hoffe ich habe die neuere Klasse erwischt. Schau nachher nochmal drüber. Würde mich auch über eine kleine Rückmeldung freuen.
MfG, Andy
PHP-Code:
<?php
/***
* Class Configuration
*
* The Configuration class allows reading a configuration-file.
* Furthermore you are able to add new entries to the configuration.
* Sure it is also possible to add, remove, edit, query and to save
* the new configuration. Finally it is important to
* mention that this class supports the structuring of the
* configuration in different sections, which sure can also
* be handled. Warning! This class can just handle existing
* configuration files.
*
* @package Configuration
* @version 0.5
* @author Andreas Wilhelm <Andreas2209@web.de>
* @copyright Andreas Wilhelm
**/
class Configuration
{
// private class-variables
private $config = array();
private $file;
/**
* Constructor - Loads configuration from path
*
* @access public
* @param Str $file
* @return NONE
*/
public function __construct($file)
{
if(file_exists($file))
{
// set path to config-file
$this->file = $file;
// save configuration to an array
$this->config = parse_ini_file($file, true);
}
else
{
throw new Exception("{$file} cannot be found.");
}
}
/**
* addItem() - Adds a new item
*
* @access: public
* @param Str $section
* @param Str $key
* @param Str $value
* @return Boolean
*/
public function addItem($section, $key, $value)
{
if( !isset($this->config[$section][$key]) )
{
$this->config[$section][$key] = $value;
return true;
}
else
{
throw new Exception("Item {$section} - {$key} already exists.");
}
}
/**
* delItem() - Removes an item
*
* @access: public
* @param Str $section
* @param Str $key
* @return Boolean
*/
public function delItem($section, $key)
{
if( isset($this->config[$section][$key]) )
{
unset($this->config[$section][$key]);
return true;
}
else
{
throw new Exception("Cannot remove {$section} - {$key}.");
}
}
/**
* setItem() - Assigns a new value to an entry of the config
*
* @access: public
* @param Str $section
* @param Str $key
* @param Str $value
* @return NONE
*/
public function setItem($section, $key, $value)
{
$this->config[$section][$key] = $value;
}
/**
* getItem() - Gets the value of an config-item
*
* @access: public
* @param Str $section
* @param Str $key
* @return String
*/
public function getItem($section, $key)
{
if( !isset($this->config[$section][$key]) )
{
throw new Exception("Cannot get item {$section} - {$key}.");
}
return $this->config[$section][$key];
}
/**
* rnItem() - Renames an item
*
* @access: public
* @param Str $section
* @param Str $from
* @param Str $to
* @return Boolean
*/
public function rnItem($section, $from, $to)
{
if( isset($this->config[$section][$from]) && !isset($this->config[$section][$to]))
{
// move data to new section
$this->config[$section][$to] = $this->config[$section][$from];
// remove old section
$this->delItem($section, $from);
return true;
}
else
{
throw new Exception("Cannot rename item {$section} - {$from}.");
}
}
/**
* addSection() - Adds a section
*
* @access: public
* @param Str $name
* @return Boolean
*/
public function addSection($name)
{
if( !isset($this->config[$name]) )
{
$this->config[$name] = array();
return true;
}
else
{
throw new Exception("Section {$name} already exists.");
}
}
/**
* delSection() - Deletes a section
*
* @access: public
* @param Str $name
* @param Boo $ifEmpty
* @return Boolean
*/
public function delSection($name, $ifEmpty = true)
{
if( isset($this->config[$name]) )
{
if( ($ifEmpty == true) && (count($this->config[$name]) > 0) )
{
throw new Exception("Section {$name} is not empty.");
}
else
{
unset($this->config[$name]);
return true;
}
}
else
{
throw new Exception("Cannot found section {$name}.");
}
}
/**
* getSection() - Returns all items of a section
*
* @access: public
* @param Str $name
* @return Array
*/
public function getSection($name)
{
$items = array();
foreach( $this->config[$name] as $key => $value )
{
$items[$key] = $value;
}
return $items;
}
/**
* getSections() - Returns all sections
*
* @access: public
* @return Array
*/
public function getSections()
{
$sections = array();
foreach( $this->config as $key => $value )
{
if( is_array($value) )
{
$sections[] = $key;
}
}
return $sections;
}
/**
* rnSection() - Renames a section
*
* @access: public
* @param Str $from
* @param Str $to
* @return Boolean
*/
public function rnSection($from, $to)
{
if( isset($this->config[$from]) && !isset($this->config[$to]))
{
// move data to new section
$this->config[$to] = $this->config[$from];
// remove old section
$this->delSection($from, false);
return true;
}
else
{
throw new Exception("Cannot rename section {$from}.");
}
}
/**
* getConfig() - Returns the whole configuration in an array
*
* @access: public
* @return Array
*/
public function getConfig()
{
return $this->config;
}
/**
* setConfig() - Creates a new Configuration from array
*
* @access: public
* @param Arr $new
* @return Boolean
*/
public function setConfig($new)
{
$this->config = $new;
return true;
}
/**
* save() - Save Configuration to file
*
* @access: public
* @return Boolean
*/
public function save()
{
$config = "; <?php die('Hacker sind nicht erwünscht.'); ?>\n";
foreach( $this->config as $key => $value)
{
if( is_array($value) )
{
// save section name
$config .= "[$key]\n";
// save section items
foreach( $value as $k => $v)
{
$config .= "$k = \"$v\"\n";
}
}
else
{
// save item
$config .= "$key = \"$value\"\n";
}
}
if( !file_put_contents($this->file, $config) )
{
throw new Exception('Cannot save configuration.');
}
}
}
?>
|

24.09.2008, 14:48:32
|
Anfänger
|
|
Registriert seit: Sep 2008
Alter: 46
Beiträge: 3
|
|
AW: REG EXPRESSION in .INI schreiben - aber wie?
Hallo Socrates!
Habe die geposteten Funktionen/Classes getestet und wunderbare Ergebnisse damit erzielt.
$meineini = new Configuration("C:/test.ini");
$meineini->addSection("Section1");
$meineini->addItem("Section2", "Folder", "C:/");
$return = $meineini->getItem("Section2", "Folder");
$meineini->addItem("Section2", "endtext", "(?=;\|\s{5}_{1,}))");
$meineini->save();
erzeugte mir beim Schreiben und Lesen korrekte RegExp´s
Inhalt der .ini:
; <?php die('Hacker sind nicht erwünscht.'); ?>
[Section1]
[Section2]
Folder = "C:/"
starttext = "(?=;\|\s{5}_{1,}))"
endtext = "(?=;\|\s{5}_{1,}))"
hat ein Weilchen gedauert bis ich das mit den Klassen anwenden konnte, aber jetzt geht´s ziemlich bequem!!
vielen Dank nochmal
Wolfgang S
|
Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)
|
|
Themen-Optionen |
|
Ansicht |
Linear-Darstellung
|
Forumregeln
|
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.
HTML-Code ist aus.
|
|
|
Alle Zeitangaben in WEZ +2. Es ist jetzt 23:21:22 Uhr.
|