Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am charlestati on github.
  • I am charlestati (https://keybase.io/charlestati) on keybase.
  • I have a public key whose fingerprint is 45E9 71ED 6B99 69AE 0AF7 C37F 6749 06F0 D219 BC0F

To claim this, I am signing this object:

@charlestati
charlestati / post.php
Created March 23, 2015 06:42
Create variables from POST values
$variables = array('username', 'age', 'city', 'street');
foreach($variables as $key) {
if(!empty($_POST[$key])) {
${key} = $_POST[$key];
} else {
${key} = '';
}
}
@charlestati
charlestati / tweets.php
Created March 23, 2015 06:42
Get tweets from a hashtag
$ch = curl_init('http://search.twitter.com/search.atom?q=' . urlencode($hashtag));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$answer = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($answer);
foreach ($xml->entry as $entry) {
$id = $entry->id;
$tweet = trim($entry->title);
$author = trim($entry->author->name);
$time = strtotime($entry->published);
@charlestati
charlestati / string.php
Created March 23, 2015 06:41
Generate a random string
$str = '';
$str_len = 31;
$pool = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
for ($i = 0; $i < $str_len; $i++) {
$str .= $pool[mt_rand(0, count($pool) - 1)];
}
@charlestati
charlestati / array.php
Created March 23, 2015 06:41
Generate an array of letters (lowercase & uppercase) and digits
array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9));
@charlestati
charlestati / colour.php
Created March 23, 2015 06:40
Generate a random color from COLOURlovers
'#' . strtolower(simplexml_load_file('http://www.colourlovers.com/api/colors/random')->color->hex);