當前位置: 首頁> 函數類別大全> stream_resolve_include_path

stream_resolve_include_path

根據include路徑解析文件名
名稱:stream_resolve_include_path
分類:溪流
所屬語言:php
一句話介紹:將相對路徑解析為絕對路徑,並且會搜索include_path 中指定的目錄來查找文件

函數名:stream_resolve_include_path()

適用版本:PHP 5 >= 5.3.2

函數描述:stream_resolve_include_path() 函數將相對路徑解析為絕對路徑,並且會搜索include_path 中指定的目錄來查找文件。

用法: string stream_resolve_include_path ( string $filename )

參數:

  • $filename: 要解析的文件路徑,可以是相對路徑或絕對路徑。

返回值: 如果找到了文件,則返回文件的絕對路徑;如果未找到文件,則返回false。

示例: 假設我們有以下的目錄結構:

  • /var/www/html/index.php
  • /var/www/includes/library.php
 // 示例1:使用相对路径$filename = '../includes/library.php'; $absolutePath = stream_resolve_include_path($filename); if ($absolutePath !== false) { echo "文件的绝对路径为:$absolutePath"; } else { echo "文件未找到"; } // 示例2:使用绝对路径$filename = '/var/www/includes/library.php'; $absolutePath = stream_resolve_include_path($filename); if ($absolutePath !== false) { echo "文件的绝对路径为:$absolutePath"; } else { echo "文件未找到"; }

輸出結果: 示例1:文件的絕對路徑為:/var/www/includes/library.php 示例2:文件的絕對路徑為:/var/www/includes/library.php

同類函數
熱門文章