Str_replace, substr, Strrpos combine to get location

Source: Internet
Author: User

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

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.