How to form a valid http url if not exists it in given url?

by barkkathulla 2014-05-31 11:06:36

Create a valid http:// url if not exists it in given url


function checkurl($input_url) {
    if (!preg_match("~^(?:f|ht)tps?://~i", $input_url)) {
        $input_url = "http://" . $input_url;
    }
    return $input_url;
}
$filtered_url = parse_url($input_url);

its very useful while getting valid image by input url.
If we miss http:// it will not upload valid image.
So before that this validation is necessary to create a valid image.
1192
like
0
dislike
0
mail
flag

You must LOGIN to add comments