Skip to content

Instantly share code, notes, and snippets.

@dfadler
Last active October 3, 2015 14:58
Show Gist options
  • Save dfadler/2473954 to your computer and use it in GitHub Desktop.
Save dfadler/2473954 to your computer and use it in GitHub Desktop.
Http and Https string Validation
<?php
// Checks a url string for http || https if its not there then http is applied
function validate_url_string( $url_string ) {
$pattern = '/^(http:\/\/|https:\/\/)/';
preg_match( $pattern, $url_string, $matches );
$url_string = count( $matches ) > 0 ? $url_string : 'http://'.$url_string;
return $url_string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment