Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is the realpath() function in PHP?

Samia Ishaque

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

Overview

The realpath function in PHP is used to find the absolute path of the specified file. An absolute path is one that contains the path from the root to the element. The general syntax for the realpath function is as follows:

realpath(string $path): string|false

Parameters

The realpath function has one mandatory parameter. This is the path, which is the file we wish to check the path for.

Return value

The realpath function returns the absolute path for a file. If it fails to retrieve the path, it returns FALSE.

Example

The following example will help you understand the realpath function. As shown below, the realpath function prints the absolute path for the file main.txt.

main.php
main.txt
<?php
echo realpath("main.txt");
?>

RELATED TAGS

php

CONTRIBUTOR

Samia Ishaque
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring