Is there any special function to parse a .conf file in php like parse_ini_file() function? If not how can I achieve that? Thanks!
EDIT :
Conf’s like httpd.conf(Apache). (I want to read and edit httpd.conf file)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there is no special function to parse httpd.conf, but a parser should be easy to write. For example, if you’re only interested in the key-value settings, like
ServerRoot /var/www, then this will do the trick:If you want to parse the
<Directory ...>and other blocks, it’ll take you a few more lines of code, but it shouldn’t be too taxing. It really depends on what you want to do. You can get a lot of info from$_SERVERandgetenv(), so you might not need to parse a config file.EDIT
In response to your update, for editing httpd.conf, you’ll need to run your script with superuser privileges and cause httpd.conf to be reloaded (e.g.,
system("apachectl graceful");).