Php disposal string

Source: Internet
Author: User
Php processing string input parameters are Maildircurusrp or Maildircurusrp. Finally, all input parameters are processed as Maildircurusrp. What are the convenient and simple methods? Thank you ------ solution javasechotrim
The input parameter is/Maildir/cur/usrp/or Maildir/cur/usrp.
Finally, it is processed as Maildir/cur/usrp.
Is there any convenient and simple method? thank you.

------ Solution --------------------
Echo trim ('/Maildir/cur/usrp /','/');
------ Solution --------------------
PHP code
$ Newstring = trim ($ string ,'/');
------ Solution --------------------
What do you mean. If it is the first character or the last character is/, remove it.
Trim functions

Echo trim ($ str, '/'); remove the '/' character at the beginning and end
------ Solution --------------------
PHP code
$ Str = "/Maildir/cur/usrp/"; $ str = substr ($ str, 0, 1) = "/"? Substr ($ str, 1): $ str; $ str = substr ($ str,-1,1) = "/"? Substr ($ str, 0,-1): $ str; echo $ str; $ str = "// Maildir/cur/usrp /////"; $ strarr = explode ("/", $ str); foreach ($ strarr as $ k => $ s) {if ($ s = "") unset ($ strarr [$ k]);} echo join ("/", $ strarr );

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.