Removing a forward-slash from the tail-end of an URL
php
Solution
$site = preg_replace('{/$}', '', $site);
This uses a relatively simple regular expression. The `$` means only match slashes at the end of the string, so it won't remove the first slash in `stackoverflow.com/questions/`. The curly braces `{}` are just delimiters; PHP requires matching characters and the front and back of regular expressions, for some silly reason.
Problem
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']); ```