spl_autoload_register php code example
Example: autoload php multiple spl_autoload_register
<?php
function autoLoader($className){
$directories = array(
'',
'classes/'
);
$fileNameFormats = array(
'%s.php',
'%s.class.php',
'class.%s.php',
'%s.inc.php'
);
$path = str_ireplace('_', '/', $className);
if(@include_once $path.'.php'){
return;
}
foreach($directories as $directory){
foreach($fileNameFormats as $fileNameFormat){
$path = $directory.sprintf($fileNameFormat, $className);
if(file_exists($path)){
include_once $path;
return;
}
}
}
}
spl_autoload_register('autoLoader');
?>