Skip to content

Instantly share code, notes, and snippets.

View MikeRogers0's full-sized avatar
🚂

Mike Rogers MikeRogers0

🚂
View GitHub Profile
@MikeRogers0
MikeRogers0 / changing-class.html
Created June 16, 2012 16:03
An introduction to jQuery
<div id="object" class="empty"></div>
<script type="text/javascript" src="http://js.fullondesign.co.uk/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
//<![CDATA[
$("#object").removeClass('empty');
$("#object").addClass('full');
//]]>
</script>
@MikeRogers0
MikeRogers0 / embarrassing-words.php
Created June 16, 2012 15:59
Checking for embarrassing words in a string
<?php
// String Cleaner – Cleans words you don't want out of strings.
// Step 1 – Define the string and the words yoiu want to remove.
$string = 'this is my silly input how cool is it?';
$words_to_remove ='silly|my|eggs'; // Seperate words with | this is regular expression.
// Step 2 – shorten the string
$string = substr($string, 0, 23); // This with return the first 23 characters (including spaces) in the string.
@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
@MikeRogers0
MikeRogers0 / meta-data.html
Created June 10, 2012 23:36
Chrome Frame
<meta http-equiv="X-UA-Compatible" content="chrome=1">
@MikeRogers0
MikeRogers0 / realpath.php
Created June 10, 2012 23:33
realpath() example
<?php
echo realpath('../');
// Would return: /home/mike/www/blogposts
?>
@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 / filter-funcs.php
Created June 10, 2012 23:28
Filter Functions in PHP
<?php
// Filter an Email Address
var_dump(filter_var('[email protected]', FILTER_VALIDATE_EMAIL)); // Returns: string(17) "[email protected]"
// 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)[email protected]', FILTER_SANITIZE_EMAIL )); // Returns: string(17) "[email protected]"
// Filter a URL
@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 / 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 / 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;}