在php的開發中咱們要包含某個文件一般的代碼是這樣的:php
<?php if(is_file($fileName)) require $flleName;
在windows,linux下運行都沒有問問題: 假設如今要包含一個 D:/web/webServer/A.php文件linux
在傳值的時誤傳了D:/web/webServer/a.php 在windows下運行時也會把D:/web/webServer/A.php包含進來,由於windows是不區分大小的,放在linux下就會報錯了web
那如作到在windows加載也能區分大小寫呢?代碼以下: windows
if(is_file($fileName)){ //PHP_OS 當前運行的操做系統 if(strstr(PHP_OS,'WIN')){ //realpath($fileName) 會轉換文件名的大小寫 /web/A.php 若是A.php不存在而a.php則會返回/web/a.php if(basename(realpath($fileName)) == basename($fileName)) require $fileName; else echo '請檢查文件的大小寫'; }else require $fileName; }
------------------------> ^^ui