Backend Development 2 min read

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
PHP realpath() Function: Description, Parameters, Return Value, and Examples

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

backendfilesystemPath Normalizationrealpath
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login 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.