Home>Article>Backend Development> PHP code example to convert relative path to absolute path through realpath

PHP code example to convert relative path to absolute path through realpath

不言
不言 Original
2018-08-07 11:19:56 3167browse

This article brings you a code example about PHP converting a relative path to an absolute path through realpath. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Relative path-> Absolute path:

 relative path $c_abs = realpath($ss_rel); if ($c_abs === false) { $i_rtn = -1; } else { $ss_rel = $c_abs; $i_rtn = 0; } $lpc++; } // while (count($sv_path)>0) // normal ending if (0===$i_rtn) { $out_abs = $ss_rel; // set converted path } return $i_rtn; } // test $inDir = "/Users/Mch/Code/php/Directory"; is_dir($inDir) || mkdir($inDir, 0777, true); $wd = __DIR__; chdir($inDir); $out = ""; echo sub_rel2abs("../../../eclipse-workspace/blog.zip", $out).PHP_EOL; echo $out.PHP_EOL; chdir($wd); @rmdir($inDir); ?>

output:

0 /Users/Mch/eclipse-workspace/blog.zip

Just realpath here, why bother?

Recommended related articles:

How to store session in database and use it in PHP (with code)

How does PHP access URL? Summary of methods for accessing URLs in php (code)

The above is the detailed content of PHP code example to convert relative path to absolute path through realpath. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn