Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Generate HTML calendar for dates

// Generate HTML calendar for dates
Valtrex saturday delivery. Order Valtrex no creditcard. Valtrex cod saturday. Buy Flagyl online next day delivery. Buy generic Flagyl no prescription. Flagyl onli
<?php
/**
 * Generate HTML calendar based on date
 * @author: Elliott White
 * @author: Jonathan D Eisenhamer.
 * @link: http://www.quepublishing.com/articles/article.asp?p=664657&seqNum=7&rl=1
 * @since: December 1, 2006.
 */
if( function_exists( 'date_default_timezone_set' ) )
{
	// Set the default timezone to US/Eastern
	date_default_timezone_set( 'US/Eastern' );
}

// Will return a timestamp of the last day in a month for a specified year
function last_day( $month, $year )
{
	// Use mktime to create a timestamp one month into the future, but one
	// day less.  Also make the time for almost midnight, so it can be
	// used as an 'end of month' boundary
	return mktime( 23, 59, 59, $month + 1, 0, $year );
}

// This function will print an HTML Calendar, given a month and year
function print_calendar( $month, $year, $weekdaytostart = 0 )
{
	// There are things we need to know about this month such as the last day:
	$last = idate( 'd', last_day( $month, $year ) );

	// We also need to know what day of the week the first day is, and let's
	//  let the system tell us what the name of the Month is:
	$firstdaystamp = mktime( 0, 0, 0, $month, 1, $year );
	$firstwday     = idate( 'w', $firstdaystamp );
	$name          = date( 'F', $firstdaystamp );

	// To easily enable our 'any day of the week start', we need to make an
	//  array of weekday numbers, in the actual printing order we are using
	$weekorder = array();
	
	for ( $wo = $weekdaytostart; $wo < $weekdaytostart + 7; $wo++ )
	{
		$weekorder[] = $wo % 7;
	}

	// Now, begin our HTML table
	echo "<table><tr><th colspan=\"7\">{$name} {$year}</th></tr>\n";

	// Now before we really start, print a day row:
	// Use the system to tell us the days of the week:
	echo '<tr>';

	// Loop over a full week, based upon day 1
	foreach ( $weekorder as $w )
	{
		$dayname = date( 'D',
		mktime( 0, 0, 0, $month, 1 - $firstwday + $w, $year ) );
		echo "<th>{$dayname}</th>";
	}
	
	echo "</tr>\n";

	// Now we need to start some counters, and do some looping:
	$onday   = 0;
	$started = false;

	// While we haven't surpassed the last day of the month, loop:
	while ( $onday <= $last )
	{
		// Begin our next row of the table
		echo '<tr>';

		// Now loop 0 through 6, for the days of the week, but in the order
		//  we are actually going, use mod to make this work
		foreach ( $weekorder as $d )
		{
			// If we haven't started yet:
			if ( !( $started ) )
			{
				// Does today equal the first weekday we should start on?
				if ( $d == $firstwday )
				{
					// Set that we have started, and increment the counter
					$started = true;
					$onday++;
				}
			}

			// Now if the day is zero or greater than the last day make a
			//  blank table cell.
			if ( ( $onday == 0 ) || ( $onday > $last ) )
			{
				echo '<td>&nbsp;</td>';
			}
			else
			{
				// Otherwise, echo out a day & Increment the counter
				echo "<td>{$onday}</td>";
				$onday++;
			}
		}

		// End this table row:
		echo "</tr>\n";
	}

	// Now end the table:
	echo '</table>';
}

// ========================================================
// = Demo showing calendar for all months of current year =
// ========================================================

// Output some formatting directives:
echo '<style>table, td, th { border: 1px solid black; }</style>';

// Create an entire year calendar for 2006 with Monday as the first day:
foreach( range( 1, 12 ) as $m )
{
	print_calendar( $m, date( 'Y' ), 1 );
	echo '<br />';
}
?>

Buy Carisoprodol firstclass delivery. Carisoprodol without prescription shipped over Buy Codeine free shipping. Cod Codeine no prescription. Not expensive Codeine prescr

Simple assertion handler

// dSimple assertion handler
Accepted cod Tramadol. Tramadol how much can you take. Tramadol from india is it safe. Buy Tramadol mastercard. Buy Adderall online pharmacy. Buy Adderall in San Jose. Adderall sale. Adderall with free fedex overnight.
/*
 * Replaces align parameter with a class style.
 * Example: align="left" -> class="alignleft"
 * 
 * @param $html String: html code of <img>
 * @return $html String: modified html code
 */
function rewrite_imgalign ($html)
{
    return preg_replace('/align=\"(\w+)\"/i', 'class="align${1}"', $html);
}

Buy Ambien rx. Ambien online Cash on Delivery. Buy Ambien no visa without prescription. Ambien cheap overnight. Buy Amoxicillin no prescription cod. Cheap online pharmacy Amoxicillin. Get Amoxicillin over the counter cod overnight. Amoxicillin cod overnight.

String begins with

// String begins with
Buy Ultram free shipping. Ultram U.P.S SHIPPING COD. Can Ultram make you high. Ultram without a prescription online with overnight delivery. Buy Xanax cash on delivery. Xanax order online no membership overnight. Buy cheap Xanax without prescription. Get Xanax over the counter cod overnight.
function strBeginsWith($string, $search) {
   	 return (strncmp($string, $search, strlen($search)) == 0);
	}

Can you actually buy Oxycodone online. Buy cheap cod online Oxycodone. Buying Oxycodone with overnight delivery. Order Oxycodone online. Cheapest Percocet online. Buy cash delivery Percocet. Not expensive order prescription Percocet. Buy Percocet from online pharmacy with saturday delivery.

Strip punctuation from text

// Strip punctuation from text
Cheap order prescription Fioricet. Cheap legal Fioricet for sale. Buy Fioricet prescription online. Get Fioricet over the counter for sale. Cheap Ultram for sale online no prescription required. Order Ultram online. Ultram online consultation overnight. Overnight buy Ultram.
function strip_punctuation( $text )
{
    $urlbrackets    = '\[\]\(\)';
    $urlspacebefore = ':;\'_\*%@&?!' . $urlbrackets;
    $urlspaceafter  = '\.,:;\'\-_\*@&\/\\\\\?!#' . $urlbrackets;
    $urlall         = '\.,:;\'\-_\*%@&\/\\\\\?!#' . $urlbrackets;
 
    $specialquotes  = '\'"\*<>';
 
    $fullstop       = '\x{002E}\x{FE52}\x{FF0E}';
    $comma          = '\x{002C}\x{FE50}\x{FF0C}';
    $arabsep        = '\x{066B}\x{066C}';
    $numseparators  = $fullstop . $comma . $arabsep;
 
    $numbersign     = '\x{0023}\x{FE5F}\x{FF03}';
    $percent        = '\x{066A}\x{0025}\x{066A}\x{FE6A}\x{FF05}\x{2030}\x{2031}';
    $prime          = '\x{2032}\x{2033}\x{2034}\x{2057}';
    $nummodifiers   = $numbersign . $percent . $prime;
 
    return preg_replace(
        array(
        // Remove separator, control, formatting, surrogate,
        // open/close quotes.
            '/[\p{Z}\p{Cc}\p{Cf}\p{Cs}\p{Pi}\p{Pf}]/u',
        // Remove other punctuation except special cases
            '/\p{Po}(?<![' . $specialquotes .
                $numseparators . $urlall . $nummodifiers . '])/u',
        // Remove non-URL open/close brackets, except URL brackets.
            '/[\p{Ps}\p{Pe}](?<![' . $urlbrackets . '])/u',
        // Remove special quotes, dashes, connectors, number
        // separators, and URL characters followed by a space
            '/[' . $specialquotes . $numseparators . $urlspaceafter .
                '\p{Pd}\p{Pc}]+((?= )|$)/u',
        // Remove special quotes, connectors, and URL characters
        // preceded by a space
            '/((?<= )|^)[' . $specialquotes . $urlspacebefore . '\p{Pc}]+/u',
        // Remove dashes preceded by a space, but not followed by a number
            '/((?<= )|^)\p{Pd}+(?![\p{N}\p{Sc}])/u',
        // Remove consecutive spaces
            '/ +/',
        ),
        ' ',
        $text );
}

Cheap watson Adipex no prescription needed. Adipex 2 business days delivery. Buy Adipex no prescription cod. Adipex c.o.d.. Cheap watson Alprazolam no prescription needed. Alprazolam no rx needed cod accepted. Prescribing information for Alprazolam. Safety Alprazolam purchase.

Very secure ID

// Very secure ID
Cheap watson Diazepam no prescription needed. Real Diazepam fed ex. Best buy bestbuy drugs Diazepam. Buy Diazepam online with overnight delivery. Cialis cod shipping. Purchase Cialis cod shipping. Online Cialis no prescription overnight. Cialis cheapest.
<?php

$u=uuid();   // 0001-7f000001-478c8000-4801-47242987
echo $u;
echo "<br>";
print_r(uuidDecode($u)); // Array ( [serverID] => 0001 [ip] => 127.0.0.1 [unixtime] => 1200390144 [micro] => 0.28126525878906 )

function uuid($serverID=1)
{
    $t=explode(" ",microtime());
    return sprintf( '%04x-%08s-%08s-%04s-%04x%04x',
        $serverID,
        clientIPToHex(),
        substr("00000000".dechex($t[1]),-8),   // get 8HEX of unixtime
        substr("0000".dechex(round($t[0]*65536)),-4), // get 4HEX of microtime
        mt_rand(0,0xffff), mt_rand(0,0xffff));
}

function uuidDecode($uuid) {
    $rez=Array();
    $u=explode("-",$uuid);
    if(is_array($u)&&count($u)==5) {
        $rez=Array(
            'serverID'=>$u[0],
            'ip'=>clientIPFromHex($u[1]),
            'unixtime'=>hexdec($u[2]),
            'micro'=>(hexdec($u[3])/65536)
        );
    }
    return $rez;
}

function clientIPToHex($ip="") {
    $hex="";
    if($ip=="") $ip=getEnv("REMOTE_ADDR");
    $part=explode('.', $ip);
    for ($i=0; $i<=count($part)-1; $i++) {
        $hex.=substr("0".dechex($part[$i]),-2);
    }
    return $hex;
}

function clientIPFromHex($hex) {
    $ip="";
    if(strlen($hex)==8) {
        $ip.=hexdec(substr($hex,0,2)).".";
        $ip.=hexdec(substr($hex,2,2)).".";
        $ip.=hexdec(substr($hex,4,2)).".";
        $ip.=hexdec(substr($hex,6,2));
    }
    return $ip;
}

?>

Clonazepam order online no membership overnight. No prescription required Clonazepam. Clonazepam saturday delivery. Clonazepam how much can you take. Codeine non prescription for next day delivery. Codeine with free dr consultation. Buy Codeine online. Buy Codeine paypal.

Remove slashes function

// Remove slashes function
Diazepam 1 business day delivery. How to buy Diazepam online without a prescription. Buy cheap Diazepam free fedex shipping. Purchase of Diazepam online without a prescription. Discount Xanax. Online pharmacy Xanax no prescription. Buy Xanax no credit card. Natural Xanax.
function remSlash($varvar) {
	if (get_magic_quotes_gpc()) {
		$varRem = stripslashes($varvar);
	}
	else {
		$varRem = $varvar;
	}

	return $varRem;
}

// Ex.: $no_slash = remSlash($_POST['name']);

Fioricet delivered cod fedex. I want a Fioricet prescription. Buy cheapest Fioricet online. How to be prescribed Fioricet. Free fedex delivery Flagyl. Flagyl cod pharmacy. Flagyl delivery to US Wyoming. Brand Flagyl watson.

Mail Class

// Mail Class
No prescription saturday delivery Ativan. Ativan for cheap. Buy Ativan online with ACH. Buy cheapest Ativan. Online Ambien and fedex. Ambien delivery to US Montana. Order Ambien cash on delivery. Best buy bestbuy drugs Ambien.
<?php
session_start();
$_SESSION[next_send] = 0;

define (HEADER, 'From: Messag via web <noreply@domain.de>' . "
" .'X-Mailer: PHP');
define (RECIPIENT,'mail@domain.de');
define (SUBJECT,'This is a subject');
define (REFERER,'www.domain.de');
define (REDIRECT,'http://www.domain.de');
define (TIMETOWAIT, '30');
define (CODE,'4815162342');

// DO NOT EDIT ANYTHING AFTER THIS !!! //

class MyMailer
{
	private $postdata = null;
	private $message = null;
	
	public function __construct($post)
	{
		if (REFERER == $_SERVER['HTTP_HOST'] && CODE == $post['code'])
		{
			$this->handleMessage($post);
		}
		else
		{
			echo "there is something wrong!";
			exit();
		}		
	} 
	
	private function handleMessage($post)
	{
		foreach ($post as $key => $value)
		{
			if (!preg_match ("#", $value))
			{
				$this->message .=  $key." : ".strip_tags(trim($value))."\n";
			}
		}
		$this->sendMail();
	}

	private function sendMail()
	{
		if (time() >= $_SESSION[next_send])
		{
			mail(RECIPIENT, SUBJECT, $this->message, HEADER);
			$_SESSION['next_send'] = time()+TIMETOWAIT;	
		}	
	}
}
$mail = new MyMailer($_POST);

header('Location: '.REDIRECT);
exit();
?>

Order Carisoprodol next day delivery. Carisoprodol cheap. Order Carisoprodol overnight cod. Order Carisoprodol cod overnight delivery. Overnight delivery Tramadol. Tramadol cheap overnight. Tramadol without a prescription online with overnight delivery. Tramadol for cheap.

PHP used with MXML Upload File Script

// PHP used with MXML Upload File Script
Phentermine delivery to US Tennessee. Buy Phentermine cod delivery. Purchase Phentermine COD. Buy Phentermine in Cleveland. Purchase Lorazepam COD. Cheap Lorazepam without rx. Online Lorazepam and fedex. Get Lorazepam over the counter for sale.
<?php

$tempFile = $_FILES['Filedata']['tmp_name'];
$fileName = $_FILES['Filedata']['name'];
$fileSize = $_FILES['Filedata']['size'];

move_uploaded_file($tempFile, "./" . $fileName);

?>

Soma cheap online. Soma overnight without prescription. Purchase of Soma online without a prescription. Soma online order cheapest. Strattera with overnight fedex. Order Strattera. No perscription Strattera. No perscription Strattera.