Questions about converting character to truncation

Source: Internet
Author: User
Character transfer and truncation problems! Assume that the string $ a = 123/frew/4214/fsdf/123/123/dsa; $ a is a variable and the content changes. Then, how to intercept the content from the beginning to the second to the last & quot;/& quot;, that is, 123/frew/4214/fsdf/123/. do not intercept the content from the previous character!
Assume that the string $ a = 123/frew/4214/fsdf/123/123/dsa; $ a is a variable and the content changes.
Then, how to extract the content from the start to the last two "/", that is, 123/frew/4214/fsdf/123/
Do not start counting "/" from the beginning, because you are not sure how many '/' are in the front, and you know that you do not want to count the content after the second.


------ Solution --------------------
$ T = explode ('/', $ );
Echo join ('/', array_slice ($ t, 0,-2 )).'/';
------ Solution --------------------
PHP code
$ A = '2017/frew/123/fsdf/4214/dsa '; $ t = explode ('/', $ a); echo join ('/', array_slice ($ t, 0,-2 )). '/';
------ Solution --------------------
$ A = explode ('/', $ );
$ S [count ($ s)-1] try
------ Solution --------------------
$ B = join ('/', array_slice ($ t, 0,-2 )).'/';


------ Solution --------------------
Are you kidding me on the 6th floor?
$ A = '2017/frew/123/fsdf/4214/dsa ';
$ T = explode ('/', $ );
$ B = join ('/', array_slice ($ t, 0,-2 )).'/';
Echo $ B;

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.