The PHP function is not able to get the directory part and the file name part of the Chinese path

Source: Internet
Author: User
The PHP function does not get the directory part and the file name part of the Chinese path.

Problem: The following two functions are available in PHP to get the directory part of a path

dirname-returns the directory portion of the path

pathinfo-returns information about the file path.

Such as:

$path _parts = PathInfo ("/www/htdocs/index.html");
echo $path _parts["DirName"]. "\ n";
echo $path _parts["basename"]. "\ n";
echo $path _parts["extension"]. "\ n";
?>
However, when the path is in Chinese, it cannot be obtained normally, only the character '. ' is returned.

Solve:

Write yourself a function to get,

function Getdir ($path)

{

return (substr ($path, 0,strrpos ($path, "\ \")));

}

It's actually a simple string processing.


Blog from the East Son

  • 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: info-contact@alibabacloud.com 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.