Cre
Cre

Reputation: 31

php how to replace slashes from beginning and end?

how to replace slashes from beginning and end?

So for example, all of these:

/this/that/

/this/that

this/that/

////////this/that////////////

... become: this/that

Upvotes: 3

Views: 173

Answers (2)

Sarfraz
Sarfraz

Reputation: 382646

Use ltrim and rtrim:

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

Result:

this/that

Upvotes: -1

Yacoby
Yacoby

Reputation: 55445

Use trim with the second argument the character(s) that you want to trim.

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

Upvotes: 10

Related Questions