Php how to replace slashes from start and end?

How to replace slashes from the beginning and the end?

So, for example, all of them:

/what's this/

/what's this

what's this/

////////what's this////////////

... become: this / that

+3
source share
2 answers

Use trim , and the second argument is the character (s) you want to trim.

$result = trim('/this/that//', '/');
//$result is now 'this/that'
+10
source

Use ltrimand rtrim:

$txt = '////////this/that////////////';
echo rtrim(ltrim($txt, '/'), '/');

Result:

this/that
-1
source

Source: https://habr.com/ru/post/1751010/


All Articles