Skip to content

Instantly share code, notes, and snippets.

@mebcomputers
mebcomputers / gist:2558567
Created Apr 30, 2012
php: get latest twitter status
View gist:2558567
class twitter {
public $twitter_base = 'http://twitter.com/statuses';
public $twitter_username = '<-username->'; //Your username here
function latest(){
$url = "$this->twitter_base/user_timeline/$this->twitter_username.xml?count=5";
$content = file_get_contents($url);
@mebcomputers
mebcomputers / gist:2551712
Created Apr 29, 2012
php: explode to array from file
View gist:2551712
<?php
$filename = "file.txt";
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
$data_array = explode(",", $data);
@mebcomputers
mebcomputers / gist:2550712
Created Apr 29, 2012
php: create visitor log file
View gist:2550712
<?php
class log {
public $filename;
public $timestamp;
public $ip;
public $u_agent;
public $u_refer;
public $ub;
View check.php
$filename = 'log.txt';
$timestamp = date('l d F Y H:i:s');
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if(preg_match('/MSIE/i',$u_agent))
{
$ub = "Internet Explorer";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
@mebcomputers
mebcomputers / gist:2505377
Created Apr 27, 2012
php: check website is running
View gist:2505377
//returns true, if domain is availible, false if not
function isDomainAvailible($domain)
{
//check, if a valid url is provided
if(!filter_var($domain, FILTER_VALIDATE_URL))
{
return false;
}
//initialize curl
@mebcomputers
mebcomputers / gist:2505353
Created Apr 27, 2012
php: auto update copyright
View gist:2505353
function autoUpdatingCopyright($startYear){
// given start year (e.g. 2004)
$startYear = intval($startYear);
// current year (e.g. 2007)
$year = intval(date('Y'));
// is the current year greater than the
// given start year?
@mebcomputers
mebcomputers / gist:2505346
Created Apr 27, 2012
php: get twiiter followers amount
View gist:2505346
function get_followers($twitter_id){
$xml=file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id);
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
$tw['count'] = $match[1];
}
return $tw['count'];
}
$nb = get_followers('phpsnippets');
@mebcomputers
mebcomputers / gist:2499697
Created Apr 26, 2012
html5: basic template
View gist:2499697
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title></title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>