简体   繁体   中英

php __DIR__ to other location

Say I have echo realpath( dirname(__DIR__) ); that points me to /usr/location

How can I use the same mechanism to point to /usr/otherplace?

Thank you, Tee

The question isn't totally clear, so I am answering it how I took it.

A simple method is to allow the file system to sort it out and just append /../otherplace

realpath( dirname(__DIR__) ) . '/../otherplace';

Otherwise you are going to have to parse the file string, which the simplest method is to use explode() , manipulate the array (In this case setting the last element to otherplace) and then use implode() to reassemble it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM