In PHP, there are also related functions for path operations.
1. parse_url
This method obtains the most detailed information, including schme, host, path, etc. This function must be known. Detailed usage can be found at http://php.net/manual/en/function.parse-url.php.
2. basename
Get the base filename of the file in url:
For example, basename(‘www.baidu.com/hell/test/ini.php’) returns ini.php;
With the second parameter, you can remove the suffix in the file name:
For example, basename(‘www.baidu.com/hell/test/ini.php’, ‘.php’) returns ini;
Also worth noting:
For example, after basename(‘www.baidu.com/hell/test/’) passes through this function, it returns test;
For specific details, please refer to http://php.net/manual/zh/function.basename.php
3. dirname
Get the path name of the file in the url:
dirname(‘www.baidu.com/hell/test/ini.php’) returns www.baidu.com/hell/test
4. pathInfo
Directly obtain the contents of dirname and basename
5. explode
Split string
6. substr
Get substring
7. join
Concatenate strings in array
8. implode
Turning an array into a string, or concatenating strings, is an alias for join. The two functions are the same.
The above has introduced a summary of the operation of paths in PHP, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.