Skip to content
PHP realpath() Function: Description, Parameters, Return Value, and Examples

PHP realpath() Function: Description, Parameters, Return Value, and Examples

This article explains PHP's realpath() function, detailing its purpose of returning a normalized absolute pathname, describing its parameters and return values, and providing two practical code examples that demonstrate path resolution on Unix and Windows systems.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community

realpath() returns a normalized absolute pathname. string realpath(string $path) The function resolves all symbolic links, removes "./", "../" and redundant slashes, and returns the canonical absolute path without any symbolic components.

Parameters

path : The path to be examined.

Return value

On success, the normalized absolute path is returned; on failure (e.g., the file does not exist) FALSE is returned.

Example 1 (Unix)

<?php
chdir('/var/www/');
echo realpath('./../../etc/passwd');
?>

Output: /etc/passwd Example 2 (Windows)

<?php
echo realpath('/windows/system32');
?>

Output:

C:\WINDOWS\System32
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendPHPFilesystemPath Normalizationrealpath
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.