Re: reg expressions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 01:50 PM 3/25/2005, you wrote:

Ok. I am really bad at regular expressions. I have to search through some files and put the contents into an array. A file could look like this:
$aliases=`cat /home/virtual/site$site_id/fst/etc/mail/local-host-names`;
----start of file----
# local-host-names - include all aliases for your machine here.
# Please do not add any domain names in this file.
domain.net
domain.com
----end of file----


In $aliases, I need to ignore the lines that start with a # sign. It is possible, but not probably that it will be more than just the first 2 lines and possible that it isn't even the first two lines. After done, $aliases should have just the two domain names in it. One per line. Then I need to loop through the lines in $aliases and do stuff with each line. Any help would be GREATLY appreciated. It would also be fine to just do a loop that checks each line. Since I guess that would be quicker. If the line starts with a #, then ignore it, otherwise, do some other stuff.

Ya know. You can look all you want, but for some reason, you never find what you are looking for until you ask somebody and then keep looking. Anyway, I found the answer. here it is:
$fc=file("/home/virtual/site$site_id/fst/etc/mail/local-host-names");
$key="#";
foreach($fc as $line){
if(!strstr($line,$key)){
}else{
echo "$line";
}
}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux