Get client current date with javascript

var currentTime = new Date()
getTime() - Number of milliseconds since 1/1/1970 @ 12:00 AM
getSeconds() - Number of seconds (0-59)
getMinutes() - Number of minutes (0-59)
getHours() - Number of hours (0-23)
getDay() - Day of the week(0-6). 0 = Sunday, ... , 6 = Saturday
getDate() - Day of the month (0-31)
getMonth() - Number of month (0-11)
getFullYear() - The four digit year (1970-9999)

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)

var currentTime = new Date();
var dat=currentTime.getFullYear() + currentTime.getMonth() + currentTime.getDate() + currentTime.getHours() + currentTime.getMinutes() + currentTime.getSeconds();

filed under: Javascript

PHP funtion to find all positions of needle in a string

function strposall($haystack,$needle){

$s=0;
$i=0;

while (is_integer($i)){

$i = strpos($haystack,$needle,$s);

if (is_integer($i)) {
$aStrPos[] = $i;
$s = $i+strlen($needle);
}
}
if (isset($aStrPos)) {
return $aStrPos;
}
else {
return false;
}
}

filed under: Usefull php functions

PHP function to strip javascript

function strip_javascript($filter){

// realign javascript href to onclick
$filter = preg_replace(“/href=(['\"]).*?javascript:(.*)?
\\1/i”, “onclick=’ $2 ‘”, $filter);

//remove javascript from tags
while( preg_match(“/<(.*)?javascript.*?\(.*?((?>[^()]+)
|(?R)).*?\)?\)(.*)?>/i”, $filter))
$filter = preg_replace(“/<(.*)?javascript.*?\(.*?((?>
[^()]+)|(?R)).*?\)?\)(.*)?>/i”, “<$1$3$4$5>“, $filter);

// dump expressions from contibuted content
if(0) $filter = preg_replace(“/:expression\(.*?((?>[^
(.*?)]+)|(?R)).*?\)\)/i”, “”, $filter);

while( preg_match(“/<(.*)?:expr.*?\(.*?((?>[^()]+)|(?
R)).*?\)?\)(.*)?>/i”, $filter))
$filter = preg_replace(“/<(.*)?:expr.*?\(.*?((?>[^()]
+)|(?R)).*?\)?\)(.*)?>/i”, “<$1$3$4$5>“, $filter);

// remove all on* events
while( preg_match(“/<(.*)?\s?on.+?=?\s?.+?(['\"]).*?\\2
\s?(.*)?>/i”, $filter) )
$filter = preg_replace(“/<(.*)?\s?on.+?=?\s?.+?
(['\"]).*?\\2\s?(.*)?>/i”, “<$1$3>“, $filter);

return $filter;
}

filed under: Usefull php functions Tagged with: , , ,

PHP function to strip html CDATA

function strip_cdata($string)
{
preg_match_all(‘//is’, $string, $matches);
return str_replace($matches[0], $matches[1], $string);
}

filed under: Usefull php functions

PHP function that strips both – tags and atributes

function strip_tags_attributes($string,$allowtags=NULL,$allowattributes=NULL){
if($allowattributes){
if(!is_array($allowattributes))
$allowattributes = explode(“,”,$allowattributes);
if(is_array($allowattributes))
$allowattributes = implode(“|”,$allowattributes);
$rep = ‘/([^>]*) (‘.$allowattributes.’)(=)(\’.*\’|”.*”)/i’;
$string = preg_replace($rep, ‘$1 $2_-_-$4′, $string);
}
if(preg_match(‘/([^>]*) (.*)(=\’.*\’|=”.*”)(.*)/i’,$string) > 0){
$string = preg_replace(‘/([^>]*) (.*)(=\’.*\’|=”.*”)(.*)/i’, ‘$1$4′, $string);
}
$rep = ‘/([^>]*) (‘.$allowattributes.’)(_-_-)(\’.*\’|”.*”)/i’;
if($allowattributes)
$string = preg_replace($rep, ‘$1 $2=$4′, $string);
return strip_tags($string,$allowtags);
}

filed under: Usefull php functions Tagged with: , ,

PHP function that verify if in a string have broken HTML tags

function broken_tags($str)
{
preg_match_all(“/(<\w+)(?:.){0,}?>/”, $str, $v1);
preg_match_all(“/<\/\w+>/”, $str, $v2);
$open = array_map(‘strtolower’, $v1[1]);
$closed = array_map(‘strtolower’, $v2[0]);
foreach ($open as $tag)
{
$end_tag = preg_replace(“/<(.*)/", "“, $tag);
if (!in_array($end_tag, $closed)) return true;
unset($closed[array_search($end_tag, $closed)]);
}
return false;
}

filed under: Usefull php functions Tagged with: , ,

Php function to strip html tags atributes

function strip_tags_attributes($string,$allowtags=NULL,$allowattributes=NULL){
$string = strip_tags($string,$allowtags);
if (!is_null($allowattributes)) {
if(!is_array($allowattributes))
$allowattributes = explode(“,”,$allowattributes);
if(is_array($allowattributes))
$allowattributes = implode(“)(? if (strlen($allowattributes) > 0)
$allowattributes = “(? $string = preg_replace_callback("/<[^>]*>/i”,create_function(
‘$matches’,
‘return preg_replace(“/ [^ =]*’.$allowattributes.’=(\”[^\"]*\”|\’[^\']*\’)/i”, “”, $matches[0]);’
),$string);
}
return $string;
}

filed under: Usefull php functions Tagged with: , ,

Is Online Fax Necessary?

Many new businesses have to fax a lot of messages, but this process can get very time consuming, especially if they don’t have some kind of system setup in order to bulk submit these faxes to their partnerships and customers. Purchasing all this faxing equipment can also become rather expensive, so you don’t really want to go the traditional approach. Converting all your files and printing them all out just to use the traditional fax machine is tedious, especially if there are better alternatives out there.

The trick is with online fax. Using the best online fax service can really significantly cut down on the amount of time you spend each day faxing out mails. How much better would it be to put more time into your business rather than messing around with a fax machine that doesn’t even work? Best of all, using an internet fax service significantly lowers costs for your business. Therefore, using this type of service should be mandatory for your company.

filed under: Other Tagged with:

PHP Class/function to dynamically create a zip file (archive)

Class: http://www.phpclasses.org/browse/package/2322.html

<?PHP

/**
* Class to dynamically create a zip file (archive)
*
* @author Rochak Chauhan
*/

class createZip {

public $compressedData = array();
public
$centralDirectory = array(); // central directory
public $endOfCentralDirectory = "\\x50\\x4b\\x05\\x06\\x00\\x00\\x00\\x00"; //end of Central directory record
public $oldOffset = 0;

/**
* Function to create the directory where the file(s) will be unzipped
*
* @param $directoryName string
*
*/

public function addDirectory($directoryName) {
$directoryName = str_replace("\\\\", "/", $directoryName);

$feedArrayRow = "\\x50\\x4b\\x03\\x04";
$feedArrayRow .= "\\x0a\\x00";
$feedArrayRow .= "\\x00\\x00";
$feedArrayRow .= "\\x00\\x00";
$feedArrayRow .= "\\x00\\x00\\x00\\x00";

$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("v", strlen($directoryName) );
$feedArrayRow .= pack("v", 0 );
$feedArrayRow .= $directoryName;

$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);
$feedArrayRow .= pack("V",0);

$this -> compressedData[] = $feedArrayRow;

$newOffset = strlen(implode("", $this->compressedData));

$addCentralRecord = "\\x50\\x4b\\x01\\x02";
$addCentralRecord .="\\x00\\x00";
$addCentralRecord .="\\x0a\\x00";
$addCentralRecord .="\\x00\\x00";
$addCentralRecord .="\\x00\\x00";
$addCentralRecord .="\\x00\\x00\\x00\\x00";
$addCentralRecord .= pack("V",0);
$addCentralRecord .= pack("V",0);
$addCentralRecord .= pack("V",0);
$addCentralRecord .= pack("v", strlen($directoryName) );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("v", 0 );
$ext = "\\x00\\x00\\x10\\x00";
$ext = "\\xff\\xff\\xff\\xff";
$addCentralRecord .= pack("V", 16 );

$addCentralRecord .= pack("V", $this -> oldOffset );
$this -> oldOffset = $newOffset;

$addCentralRecord .= $directoryName;

$this -> centralDirectory[] = $addCentralRecord;
}

/**
* Function to add file(s) to the specified directory in the archive
*
* @param $directoryName string
*
*/

public function addFile($data, $directoryName)   {

$directoryName = str_replace("\\\\", "/", $directoryName);

$feedArrayRow = "\\x50\\x4b\\x03\\x04";
$feedArrayRow .= "\\x14\\x00";
$feedArrayRow .= "\\x00\\x00";
$feedArrayRow .= "\\x08\\x00";
$feedArrayRow .= "\\x00\\x00\\x00\\x00";

$uncompressedLength = strlen($data);
$compression = crc32($data);
$gzCompressedData = gzcompress($data);
$gzCompressedData = substr( substr($gzCompressedData, 0, strlen($gzCompressedData) - 4), 2);
$compressedLength = strlen($gzCompressedData);
$feedArrayRow .= pack("V",$compression);
$feedArrayRow .= pack("V",$compressedLength);
$feedArrayRow .= pack("V",$uncompressedLength);
$feedArrayRow .= pack("v", strlen($directoryName) );
$feedArrayRow .= pack("v", 0 );
$feedArrayRow .= $directoryName;

$feedArrayRow .= $gzCompressedData;

$feedArrayRow .= pack("V",$compression);
$feedArrayRow .= pack("V",$compressedLength);
$feedArrayRow .= pack("V",$uncompressedLength);

$this -> compressedData[] = $feedArrayRow;

$newOffset = strlen(implode("", $this->compressedData));

$addCentralRecord = "\\x50\\x4b\\x01\\x02";
$addCentralRecord .="\\x00\\x00";
$addCentralRecord .="\\x14\\x00";
$addCentralRecord .="\\x00\\x00";
$addCentralRecord .="\\x08\\x00";
$addCentralRecord .="\\x00\\x00\\x00\\x00";
$addCentralRecord .= pack("V",$compression);
$addCentralRecord .= pack("V",$compressedLength);
$addCentralRecord .= pack("V",$uncompressedLength);
$addCentralRecord .= pack("v", strlen($directoryName) );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("v", 0 );
$addCentralRecord .= pack("V", 32 );

$addCentralRecord .= pack("V", $this -> oldOffset );
$this -> oldOffset = $newOffset;

$addCentralRecord .= $directoryName;

$this -> centralDirectory[] = $addCentralRecord;
}

/**
* Fucntion to return the zip file
*
* @return zipfile (archive)
*/

public function getZippedfile() {

$data = implode("", $this -> compressedData);
$controlDirectory = implode("", $this -> centralDirectory);

return
$data.
$controlDirectory.
$this -> endOfCentralDirectory.
pack("v", sizeof($this -> centralDirectory)).
pack("v", sizeof($this -> centralDirectory)).
pack("V", strlen($controlDirectory)).
pack("V", strlen($data)).
"\\x00\\x00";
}

/**
*
* Function to force the download of the archive as soon as it is created
*
* @param archiveName string - name of the created archive file
*/

public function forceDownload($archiveName) {
$headerInfo = '';

if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

// Security checks
if( $archiveName == "" ) {
echo
"<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> The download file was NOT SPECIFIED.</body></html>";
exit;
}
elseif ( !
file_exists( $archiveName ) ) {
echo
"<html><title>Public Photo Directory - Download </title><body><BR><B>ERROR:</B> File not found.</body></html>";
exit;
}

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($archiveName).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($archiveName));
readfile("$archiveName");

}
}
?>

filed under: Usefull php functions Tagged with: ,

Get real IP address if user has transportent proxy

<?PHP

function getip()
{
if (
getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"),"unknown"))
$ip = getenv("HTTP_CLIENT_IP");

elseif (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");

elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");

elseif (!empty($_SERVER['REMOTE_ADDR']) && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];

else
$ip = "unknown";

return($ip);
}
?>

filed under: Usefull php functions Tagged with: , ,
Copyright © 2009 PHPcustom.com . All rights reserved.
Designed by Theme Junkie . Powered by WordPress.