note 75140 deleted from function.preg-match by nlopess
| From: | nlopess@php.net | Date: | Tue, 15 May 2007 13:49:17 +0000 |
| Subject: | note 75140 deleted from function.preg-match by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126613@lists.php.net to get a copy of this message | ||
Note Submitter: loathsome
----
Here's a function that will return a proper formated URL. As WWW is deprecated, it strips away
any attempt of WWW in the URL.
<?php
//
// Proper URL function
// by Christian Meinhold - loathsome.us
//
function proper_url($input){
// check if it's a proper formed URL
if(preg_match("/^(.*)\.(.*)$/", $input)){
if(!preg_match("/^http:\/\/(.*)$/", $input)){
$result = 'http://' . $input;
}
else {
$result = $input;
}
// www is deprecated
if(preg_match("/http:\/\/www\./i", $result)){
$result = str_ireplace('www.', '', $result);
}
}
else {
return false;
}
// return final string
return $result;
}
# END FUNCTION
$url = 'www.bullshit.loathsome.us';
// http://bullshit.loathsome.us
echo (proper_url($url) ? proper_url($url) : 'Invalid URL');
?>