Skip to content

Instantly share code, notes, and snippets.

@grim-reapper
Last active August 29, 2015 14:06
Show Gist options
  • Save grim-reapper/9d3d1bcb3f6522f8ba83 to your computer and use it in GitHub Desktop.
Save grim-reapper/9d3d1bcb3f6522f8ba83 to your computer and use it in GitHub Desktop.
PHP: Url Prefixer
<?php
/**
* Prefix_protocol This function will search for http://, https://, ftp:// and ftps://, if none of them are in the string then we add the prefix to the start of the string
* @param string $url get url
* @param string $prefix prefixer
* @return string return full url with protocol
* @author Mind Cracker <[email protected]>
*/
function prefix_protocol($url,$prefix='http://')
{
if (! preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = $prefix.$url;
}
return $url;
}
// returns http://paulund.co.uk
prefix_protocol('paulund.co.uk');
// returns https://paulund.co.uk
prefix_protocol('paulund.co.uk', 'https://');
// returns ftp://paulund.co.uk
prefix_protocol('paulund.co.uk', 'ftp://');
// returns ftps://paulund.co.uk
prefix_protocol('paulund.co.uk', 'ftps://');
// returns http://paulund.co.uk
prefix_protocol('http://paulund.co.uk');
// returns https://paulund.co.uk
prefix_protocol('https://paulund.co.uk');
// returns ftp://paulund.co.uk
prefix_protocol('ftp://paulund.co.uk');
// returns ftps://paulund.co.uk
prefix_protocol('ftps://paulund.co.uk');
?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '1396167917281191',
xfbml : true,
version : 'v2.1'
});
FB.getLoginStatus(function(stsResp) {
if(stsResp.authResponse) {
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', {
// message : "Hope you guys would like it bcoz JS SDK is all the time Great!",
// link : 'http://www.rontranmer.com/wp-content/uploads/2011/07/poetry3.jpg',
picture : 'http://adaabeishq.com/wp-content/uploads/2012/12/Sad-Urdu-Poetry-1.jpg'
// name : 'Mind Cracker ;)',
// description : 'Hmmmm! What do you say about it?'
}, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
console.log('Post ID: ' + response.id);
}
});
} else {
FB.login(function(loginResp) {
if(loginResp.authResponse) {
getUserInfo();
} else {
alert('Please authorize this application to use it!');
}
});
}
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<div
class="fb-like"
data-send="true"
data-width="450"
data-show-faces="true">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment