A modified version of @nickf code:
function addhttp($url) {
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
return $url;
}
Recognizes ftp://
, ftps://
, http://
and https://
in a case insensitive way.
More Related Contents:
- PHP – Replace part of a string [closed]
- PHP validation/regex for URL
- PHP regular expressions: No ending delimiter ‘^’ found in
- Replace URLs in text with HTML links
- Remove non-utf8 characters from string
- remove script tag from HTML content
- Capturing text between square brackets in PHP
- get everything between and with php [duplicate]
- How do I remove all specific characters at the end of a string in PHP?
- How exactly do Regular Expression word boundaries work in PHP?
- How can I use .htaccess to hide .php URL extensions?
- PHP – regex to allow letters and numbers only
- preg_match() Unknown modifier ‘[‘ help
- Can someone explain the /e regex modifier? [duplicate]
- How do I replace double quotes with single quotes
- Extracting all values between curly braces regex php
- How to “Validate” Human Names in CakePHP?
- In PHP, how do I extract multiple e-mail addresses from a block of text and put them into an array?
- How to remove diacritics from text?
- PHP using preg_replace : “Delimiter must not be alphanumeric or backslash” error
- PHP regular expression to match lines starting with a special character
- Using regex to filter attributes in xpath with php
- Get last whole number in a string
- RegExp in preg_match function returning browser error
- Regex for password PHP [duplicate]
- regular expression and forward slash
- PHP – detect whitespace between strings
- What is the MM/DD/YYYY regular expression and how do I use it in php?
- Finding @mentions in string
- PHP: Escape RegEx pattern to prevent being applied?