You are here: Re: [PHP] reg expressions « PHP « IT news, forums, messages
Re: [PHP] reg expressions

Posted by Matthew Fonda on 03/26/05 03:56

I wouldnt recommend using a regular expression for this. Regular
expressions most of the time are now the answer. You could just do
something like:

foreach ($line as file('/home/virtual/....')) {
if (substr(trim($line), 0, 1) == '#') {
//$line is a comment
} else {
//$line is not a comment
}
}

On Fri, 2005-03-25 at 11:50, Steve Buehler 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.
>
> Thanks
> Steve
--
Regards,
Matthew Fonda
http://mfonda.info

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация