Skip to content

Instantly share code, notes, and snippets.

View MikeRogers0's full-sized avatar
🚂

Mike Rogers MikeRogers0

🚂
View GitHub Profile
@MikeRogers0
MikeRogers0 / braces.php
Created June 10, 2012 22:38
Braces Example
<?php
/* Examples of annoying code */
if ( $coder === 'Silly' ) bang_head();
while ( $coder === 'Silly' )
bang_head();
endwhile;
/* Examples of good code*/
if ( $coder !== 'Silly' ){ Drink_Beer(); }
@MikeRogers0
MikeRogers0 / conditional-comments.html
Created June 10, 2012 22:51
Conditional Comments
<!–[if IE]>
This will only show for Internet Explorer (IE)
<![endif]–>
<!–[if !IE]>
This will only show if the client is not using IE.
<!–[endif]>
<![if IE 6]–>
Only shows on IE6
<!–[endif]>
<![if lte IE 6]–>
@MikeRogers0
MikeRogers0 / recent-stumbles.php
Created June 10, 2012 22:53
Displaying Recent Stumbles (From StumbleUpon)
<?php # File created on 3rd April 2009 by Mike Rogers (http://www.fullondesign.co.uk/).
/*
function – recent_stumbles(string $username [, string $type= NULL [, int $limit = 5]])
$username – The stumbleupon username, such as rogem002
$type – Default: NULL – What you want to limit your rss to show. Can be NULL, blog, comments, favorites or reviews
$limit – Default: 5 – how many tweets you wish to show, must be numeric.
*/
function recent_stumbles($username, $type=NULL, $limit=5){
if(!is_numeric($limit)){$limit = 5;}
if($type !== NULL && $type !== 'blog' && $type !== 'comments' && $type !== 'favorites' && $type !== 'reviews'){$type = NULL;}
@MikeRogers0
MikeRogers0 / recent-tweets-via-rss.php
Created June 10, 2012 22:55
Displaying Recent Tweets via Twitter’s RSS
<?php # File created on 1st April 2009 by Mike Rogers (http://www.fullondesign.co.uk/).
/*
function – recent_tweets(string $username [, int $limit = 5])
$username – Your twitter username, such as rogem002
$limit – Default: 5 – how many tweets you wish to show, must be numeric.
*/
function recent_tweets($username, $limit=5){
if(!is_numeric($limit)){$limit = 5;}
$xml = simplexml_load_file('http://search.twitter.com/search.atom?q=from%3A'.urlencode($username));
@MikeRogers0
MikeRogers0 / md5-plus-salt.php
Created June 10, 2012 23:21
Securing Passwords in PHP
<?php
$salt = '%$£Salt_Here*(&^';
$password = md5('password'.$salt);
// $password will now return 5747563a265df7a3250884394c0a05e0
?>
@MikeRogers0
MikeRogers0 / filter-funcs.php
Created June 10, 2012 23:28
Filter Functions in PHP
<?php
// Filter an Email Address
var_dump(filter_var('email@example.com', FILTER_VALIDATE_EMAIL)); // Returns: string(17) "email@example.com"
// This is a fake email being filtered.
var_dump(filter_var('fake_mail.com', FILTER_VALIDATE_EMAIL)); // Returns: bool(false)
var_dump(filter_var('ema(i)l@example.com', FILTER_SANITIZE_EMAIL )); // Returns: string(17) "email@example.com"
// Filter a URL
@MikeRogers0
MikeRogers0 / shorten.php
Created June 10, 2012 23:30
URL Shortening Function
<?php
function shorten_url($url, $service=NULL){
if($service== 'tinyurl'){return get_link('http://tinyurl.com/api-create.php?url='.urlencode($url));}
elseif($service == 'urly'){return get_link('http://ur.ly/new.txt?href='.urlencode($url));}
elseif($service == 'isgd'){return get_link('http://is.gd/api.php?longurl='.urlencode($url));}
elseif($service == 'klam'){return get_link('http://kl.am/api/shorten/?format=text&url='.urlencode($url));}
elseif($service == 'unu'){return get_link('http://u.nu/unu-api-simple?url='.urlencode($url));}
else{return get_link('http://api.tr.im/v1/trim_simple?url='.urlencode($url));}
return $url;
}
@MikeRogers0
MikeRogers0 / realpath.php
Created June 10, 2012 23:33
realpath() example
<?php
echo realpath('../');
// Would return: /home/mike/www/blogposts
?>
@MikeRogers0
MikeRogers0 / meta-data.html
Created June 10, 2012 23:36
Chrome Frame
<meta http-equiv="X-UA-Compatible" content="chrome=1">
@MikeRogers0
MikeRogers0 / errors.php
Created June 16, 2012 15:42
Handling Errors In PHP
<?php
/*
errors class – Helps management of errors in a script.
@version
1.0
@author
Mike Rogers (FullOnDesin.co.uk)
@last updated
03 June 2009