read/write constants

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sanders
Forum Newbie
Posts: 4
Joined: Sun Jun 12, 2005 12:55 am

read/write constants

Post by sanders »

Hi

I want to read/write constants in a file. To change the config with a browser.

<input type="text" name="testconstant">

output/change in a file
define("TESTCONSTANT", "Hello world.");

Is there a class for that?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Doubt that.
You'll have to write code to open the file and change the contant values by examining the lines.
Regular Expressions can be used for this.
sanders
Forum Newbie
Posts: 4
Joined: Sun Jun 12, 2005 12:55 am

Post by sanders »

Hi
Regular Expressions can be used for this
OK, but I hope there is already a solution. Found this: http://pear.php.net/package/Config

Have someone experience with that?
sanders
Forum Newbie
Posts: 4
Joined: Sun Jun 12, 2005 12:55 am

Post by sanders »

Hi

Another one
http://www.zend.com/manual/function.bco ... nstant.php
But only in PHP5?

I tried it with Regular Expressions. Not my world.

Has anybody a easy solution to handle this?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Filter for it in your config file?

Code: Select all

if(isset($_GET['testconstant'])) {
    define("TESTCONSTANT", $_GET['testconstant']);
} else {
    define("TESTCONSTANT", "Hello world.");
}
Could use a little data checking too.
sanders
Forum Newbie
Posts: 4
Joined: Sun Jun 12, 2005 12:55 am

Post by sanders »

OK, thanks, but it must written statically in the config-file, not temporary. And I don't know, the Constants-Name (e.G. TESTCONSTANT) and how much Constants are in the file. It must be dynamic.

I think there is no existent solution for that (after 5 hours Google-Search). Probably I have to learn Regular Expressions. Arrggh.
Post Reply