How can i remove the first or last character from a string in php?

http://www.example.com/backkết thúc.php?c=crud&m=index&t=care ^removing the / after the backend.php?. Any ideas on the best way lớn vị this?

Thanks!


*

*

I think that it"s better khổng lồ use simply str_replace, lượt thích the manual says:

If you don"t need fancy replacing rules (like regular expressions), you should always use this function instead of ereg_replace() or preg_replace().

Bạn đang xem: How can i remove the first or last character from a string in php?


*

*

While a regexp would suit here just fine, I"ll present you with an alternative sầu method. It might be a tad faster than the equivalent regexp, but life"s all about choices (...or something).

$length = strlen($urlString);for ($i=0; $iWeird, I know.

Xem thêm: Bà Bầu Ăn Gì Để Sinh Con Gái Da Trắng Bóc, Bà Bầu Ăn Gì Để Con Da Trắng


*

$splitPos = strpos($url, "?/");if ($splitPos !== false) $url = substr($url, 0, $splitPos) . "?" . substr($url, $splitPos + 2);
Thanks for contributing an answer khổng lồ Staông xã Overflow!

Please be sure to answer the question. Provide details và nói qua your research!

But avoid

Asking for help, clarification, or responding to other answers.Making statements based on opinion; bachồng them up with references or personal experience.

Xem thêm: Phần Mềm Pps Là Gì - Phần Mở Rộng Tệp Pps

To learn more, see our tips on writing great answers.


Post Your Answer Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy


Not the answer you're looking for? Browse other questions tagged php string or ask your own question.


site kiến thiết / biểu tượng logo © 2021 Staông xã Exchange Inc; user contributions licensed under cc by-sa. rev2021.6.1.39387


Your privacy

By clicking “Accept all cookies”, you agree Staông xã Exchange can store cookies on your device & discthảm bại information in accordance with our Cookie Policy.


Chuyên mục: