RE: preg_match

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

 



> -----Original Message-----
> From: Stut [mailto:stuttle@xxxxxxxxx]
> Sent: 27 October 2008 15:21
> To: Alex Chamberlain
> Cc: PHP General list
> Subject: Re:  preg_match
> 
> On 27 Oct 2008, at 15:08, Alex Chamberlain wrote:
> > I don’t understand regular expressions at all – I will make an
> > effort to
> > learn about them one day, but I need a solution today. I want to use
> > the
> > __autoload function, but not for all my class only those that finish
> > in
> > ‘Controller’. So for instance,
> >
> > ‘ErrorController’ should load ‘errorcontroller.inc.php’
> > ‘IndexController’ should load ‘indexcontroller.inc.php’
> > ‘FooBar’ should NOT load anything whatsoever.
> >
> > Can you help me write an __autoload function please??
> 
> Have you even tried it? This is not hard, and doesn't need to use any
> regular expressions at all.
> 
> We're not here to write code for you, we're here to help when you have
> problems. Try it, see how far you get and send us the code if/when you
> get stuck.
> 
> Unless you want to hire me to do it. My rates are pretty reasonable
> for simple stuff like this.
> 
> -Stut

Problem solved:
function __autoload($c) {
  $m = array();
  preg_match('/(?:^[A-Z][a-z]+)Controller/', $c, $m);
  if (count($m)) {
   require_once(realpath(FS_CONTROLLER . '/' . strtolower($m[0]) .
'.inc.php'));
  }
 }

However (perhaps a more appropriate question), do you think there is an
easier/better way to do this??

Alex

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com 
Version: 8.0.175 / Virus Database: 270.8.3/1748 - Release Date: 27/10/2008
07:57


-- 
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