PHP Gets the current directory relative to the domain name, PHP gets the present directory

Source: Internet
Author: User
Tags zend framework
PHP Gets the current directory relative to the domain name, PHP gets the current directory

This article reproduced from:??? Http:[email protected]/blog/static/166335404201122322635868/


For example, this address, I want to get the address of the red zone for the link within the generated station, named BaseURL.
With $_server[' Script_name '), $_server[' Script_name ' is the relative path of the PHP file that is currently being accessed, as long as it is handled as follows:

//Get the directory part from $_server[' Script_name '] and replace the backslash problem that may occur with the DirName function ??

$BASEURL ?=? Str_replace (' \ \ ', '/', dirname ($_server['script_name'));

//Guaranteed to be empty when can return the normal value that can be used ?

$baseUrl? =?empty ($BASEURL)??? ' / '?:?' / '. Trim ($BASEURL, '/'). ' /';??

This will normally get to the directory address of the /dev/classd/ section.

By the way, the Zend Framework of the BASEURL () function, the results of a look at a lot of code will not continue to see, I can not think of the same function he used a lot of code, from the $_server to get a bunch, and then the middle through two or three classes, Four or five methods to finally be called directly by us, in addition to the middle of three lines is to get the current PHP file, the others are useless and meaningless processing, ZF itself is already running slow enough, what is the meaning of it.






  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.