adding lines to a file

From: Date: Mon, 10 Jul 2000 16:39:29 +0000
Subject: adding lines to a file
Groups: php.general 
Request: Send a blank email to php-general+get-5752@lists.php.net to get a copy of this message
i need to add various lines to the httpd.conf file, via php script. i use this to search through and find the line that contains ServerName domain.com , and it returns what line that is. $file_httpd = file($httpd_conf); while( list($no,$line) = each ($file_httpd) ) { if(preg_match ("/ServerName\s+(.*)/i",$line,$match)){ if($match[1] == $domain){ echo $no + 1 ."\n"; //add 1 to make place it on the right line. break; } } } There is probably a much easier way, but im not that good yet ;) now what i need to do, is find the closing </VirtualHost> container, and then prepend 3 lines right before the closing directive. this is a sample, 1 # -FrontPage- version=4.0 2 ## ... 427 428 <VirtualHost ip> 429 ServerAdmin webmaster@domain.org 430 DocumentRoot /home/user/public_html 431 ServerName domain.org 432 ServerAlias www.domain.com 433 User user 434 Group cust 435 ErrorLog /home/user/logs/error_log 436 CustomLog /home/user/logs/access_log common 437 </VirtualHost> 438 439 .. start of next v host i need to instert 3 new lines starting at line 437. I also noticed that the above expression returns line number any ideas ???

« previous php.general (#5752) next »