Function addhttp: Add HTTP to Hyperlink if not exists

<? $url = "example.de"; function addhttp($url) { if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { $url = "http://" . $url; } return $url; } echo addhttp($url); // Returns: http://example.de

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.