WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem Update Picture
Andy Krause
Date : Nov 22nd 2000
Grade : Be the 1st to grade this Code Example
Viewed : 4939
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Andy Krause
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

As I found thousands of sample how to use ereg, replace and file functions, but no proper
answer on how to edit a config-file (I became too so lazy to manually edit all this stuff :)), I
wrote some code myself and the first part is here.

Usage: http://confedit.php?
strCfgFile=YOUR_CONFIG_FILE&strCfgVar=THE_VAR_TO_MODIFY&strCfgVal=THE_NEW_VALUE

Here's the content for confedit.php:

------ CUT ----------------

<?

$strOldContent = file ($strCfgFile);
$strNewContent = "";
while (list ($intLineNum, $strLine) = each ($strOldContent))
{
if(!eregi("^//",$strLine)) // dont show any line commented with //
{
if(eregi("^\\$".$strCfgVar."( |\t)*=",$strLine))         // show any line beginning with a $
{
$strLineParts=explode("=",$strLine);

// here we should have to determine type of value! (BOOL, INT or String)

if("$".$strCfgVar == trim($strLineParts[0]))
        {
        $strLineParts[1] = "\t\"".$strCfgVal."\"";
        $strLine = implode("=",$strLineParts).";\r\n";
        }
}
}
$strNewContent .= $strLine;
$fp = fopen($strCfgFile."_new", "w");
fputs($fp,$strNewContent);
fclose($fp);
}
copy($strCfgFile."_new",$strCfgFile);

echo "<pre>The value for <b>$$strCfgVar</b> has been replaced with <b>$strCfgVal</b> in
File <b>$strCfgFile</b></pre>";

?>

----- End CUT ----

As I did not have the time yet to explore all power of regular expressions, I dont mind, a Guru
finding a more elegant solution for the first two ereg-statement to merge them.

Otherwise, this little script will end up in a complete app, with which one can (finally) simply
configure and setup all kind of php-apps, which require many times heavy editing.

The full version will include form-based editing. Any comments are very welcome, esp. hints, if
such script already exists (could save me more time ;)

Enjoy


n-dee (aka ARK)


?>



Show Source with Line Numbers
Categories : PHP, Regexps, Filesystem
A simple configuration file editor to ease you life in setting up php applications. Reads variables from a given file automatically and displays current value. New value will be written to file after submit.
Categories : PHP, Filesystem, Regexps, Java Script
Massreplace
Categories : Filesystem, Regexps, Strings, PHP
Check if a file exists on a remote FTP server with PHP
Categories : PHP, FTP, Regexps
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Introduction to Language Files
Categories : PHP, Filesystem, Beginner Guides
A flat file counter
Categories : PHP, Cookies, Filesystem, Beginner Guides
Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed
Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS)
Display list of files within current and subdirectories (recursively) showing each file as an anchored link and each directory as a category header.
Categories : Filesystem, Directories, Arrays, PHP
ereg -- Regular expression match
Categories : PHP, PHP Functions, Regexps
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
BBCode Formatting String
Categories : PHP, HTML, Regexps, Arrays
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
I need a trim function/regexp that will trim all " " from the ends of a string.
Categories : Regexps, PHP, Strings
Random Image Display
Categories : PHP, Filesystem, Graphics, HTML and PHP
 Andy Krause wrote :481
stupid me - 
the first eregi-statement is not necessary, if I just want to parse all lines starting with a "$".

n-dee