Could someone please help me with a regular expression (I need it in php and in js) to remove http:// and www. from the beginning of a url string and remove the trailing / if its there.
For Example
-
http://www.google.com/
would begoogle.com
-
https://yahoo.com?page=1
would beyahoo.com?page=1
-
fancysite.com/articles/2012/
would befancysite.com/articles/2012
Heres the code Im using for the JS side:
row.page_href.replace(/^(https?|ftp):\/\//, '')
And heres the code Im using for the php side:
$urlString = rtrim($urlString, '/');
$urlString = preg_replace('~^(?:https?://)?(?:www[.])?~i', '', $urlString);
As you can see the JS regex only removes http:// currently and the php requires two steps to do everything.