how you can code a PHP function who'll check if the mode of Apache is on safemode or otherwise ?

<?php 
// Check for safe mode
if( ini_get('safe_mode') ){
    // Do it the safe mode way
}else{
    // Do it the regular way
}

?>

http://www.php.net/manual/en/features.safe-mode.php#45263

Apache does not possess a safemode, Would you mean PHP?

$safemode = ini_get('safe_mode');