Source Code:
(back to article)
<?php // Define the URL $url = "www.example.com"; // Check if the URL does not have a protocol if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { // Add the HTTP protocol to the URL $url = "http://" . $url; } // Output the URL echo "The URL is: " . $url; ?>
Result:
Report an issue