Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
483 views
in Technique[技术] by (71.8m points)

php - Removing a forward-slash from the tail-end of an URL

The code below removes "www.", etc. from the beginning of websites that are entered into a database. It works great.

Is there a way I could use similar code to remove a forward-slash from the tail-end of a website that is entered into the same database?

$remove_array = array('http://www.', 'http://', 'https://', 'https://www.', 'www.');
$site = str_replace($remove_array, "", $_POST['site']);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can pass a string of characters that you want trimmed off of a string to the trim family of functions. Also, you could use rtrim to trim just the end of the string:

$site = rtrim($site, "/");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...