The relevant code is as follows
Str_replace---Replace all occurrences of the searched string substitution string define (' Db_dir ', str_replace ("\ \", '/', dirname (__file__))),//Get the file current position define (' Root_dir ', substr (Db_dir,0,strrpos (substr (Db_dir,0,strrpos (Db_dir, '/')), '/')); By getting the file current position, up to level two directory
Constant Root_dir, by obtaining such as Db_dir is D:/STUDY/WWW/AAA/BBB/CCC
The last/to intercept the character, and then by the last/to intercept the character, this is the top level two directory
D:/study/www/aaa
Go offline to introduce
I. Definition and usage of str_replace
The Str_replace () function replaces some characters in a string with other characters ( case-sensitive ).
The function must adhere to the following rules:
- If the searched string is an array, it returns the array.
- If the searched string is an array, it will find and replace each element in the group.
- If you need to find and replace an array at the same time, and you need to execute the replacement element less than the number of elements found, the extra element is replaced with an empty string
- If you are looking for an array, instead of a string, the substitution string will work for all found values.
Note: The function is case-sensitive. Use the Str_ireplace () function to perform a case-insensitive search.
Note: This function is binary safe.
Ii. definition and usage of substr
The substr () function returns a portion of a string.
Note: if the start parameter is negative and length is less than or equal to start, length is 0.
Iii. definition and usage of Strrpos
The Strrpos () function finds the position of the last occurrence of a string in another string.
notes: the Strrpos () function is case-sensitive .
Strrpos related functions :
- Stripos ()-finds the position of the first occurrence of a string in another string (case insensitive)
- Strpos ()-finds the position of the first occurrence of a string in another string (case-sensitive)
- Strripos ()-Finds the last occurrence of a string in another string (case insensitive)
Str_replace, substr, Strrpos combine to get location