note 75140 added to function.preg-match
| From: | loathsome at osu1 dot php dot net | Date: | Tue, 15 May 2007 01:25:37 +0000 |
| Subject: | note 75140 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-126591@lists.php.net to get a copy of this message | ||
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');
?>
----
Server IP: 128.39.198.38
Probable Submitter: 84.48.75.189
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/75140
Del: integrated -- https://master.php.net/note/delete/75140/integrated
Del: useless -- https://master.php.net/note/delete/75140/useless
Del: bad code -- https://master.php.net/note/delete/75140/bad+code
Del: spam -- https://master.php.net/note/delete/75140/spam
Del: non-english -- https://master.php.net/note/delete/75140/non-english
Del: in docs -- https://master.php.net/note/delete/75140/in+docs
Del: other reasons-- https://master.php.net/note/delete/75140
Reject -- https://master.php.net/note/reject/75140
Search -- https://master.php.net/manage/user-notes.php