LoRz

Tuesday, January 26, 2010

 

Check and Uncheck checkboxes using jQuery

<script type="text/javascript">
function checkAll(id, name, flag)
{
if (flag == 0)
{
$("form#" + id + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
}
else
{
$("form#" + id + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
}
}
</script>

<form id="invite" method="post">
<input type="checkbox" id="accept" name="accept" value="1">
<input type="checkbox" id="accept" name="accept" value="2">
<input type="button" value="Check All" onclick="checkAll('invite', 'accept[]', 1);"/>
<input type="button" value="Uncheck All" onclick="checkAll('invite', 'accept[]', 0);"/>
</form>

Friday, October 30, 2009

 

Search between a string using delimeters


function strbet($inputStr, $delimeterLeft, $delimeterRight, $debug=false)
{
$posLeft = strpos($inputStr, $delimeterLeft);

if ($posLeft===false)
{
if ($debug)
{
echo "Warning: left delimiter '{$delimeterLeft}' not found";
}
return false;
}

$posLeft += strlen($delimeterLeft);
$posRight = strpos($inputStr, $delimeterRight, $posLeft);

if ($posRight===false)
{
if ($debug)
{
echo "Warning: right delimiter '{$delimeterRight}' not found";
}

return false;
}

return substr($inputStr, $posLeft, $posRight-$posLeft);
}

Wednesday, September 23, 2009

 

Fix `ereg is deprecated` errors in PHP 5.3



To migrate ereg():
ereg('\.([^\.]*$)', $this->file_src_name, $extension);


to

preg_match('/\.([^\.]*$)/', $this->file_src_name, $extension);


To migrate ereg_replace():
$this->file_dst_name_body = ereg_replace('[^A-Za-z0-9_]', '', $this->file_dst_name_body);


to

$this->file_dst_name_body = preg_replace('/[^A-Za-z0-9_]/', '', $this->file_dst_name_body);


To migrate eregi():
eregi('\.([^\.]*$)', $this->file_src_name, $extension);


to

preg_match('/\.([^\.]*$)/i', $this->file_src_name, $extension);

Thursday, July 30, 2009

 

How to check when a website was last updated

Type in the address bar

javascript:alert(document.lastModified)

Monday, July 20, 2009

 

Chase Paymentech

PHP code for Chase Paymentech

<?php

$url = "https://orbitalvar2.paymentech.net"; // use while in certification/testing
//$url = "https://orbital1.paymentech.net"; // use for production

$post_string="
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Request>
<NewOrder>
<IndustryType>EC</IndustryType>
<MessageType>AC</MessageType>
<BIN>000002</BIN>
<MerchantID>700000008906</MerchantID>
<TerminalID>001</TerminalID>
<CardBrand>VI</CardBrand>
<AccountNum>4012888888881</AccountNum>
<Exp>1206</Exp>
<CardSecValInd>1</CardSecValInd>
<CardSecVal>1234</CardSecVal>
<AVSzip>1234</AVSzip>
<AVSaddress1>address</AVSaddress1>
<AVScity>Orlando</AVScity>
<AVSstate>FL</AVSstate>
<AVSname>Michael Loria</AVSname>
<OrderID>abcd</OrderID>
<Amount>6060</Amount>
<Comments>Email: </Comments>
<ShippingRef></ShippingRef>
</NewOrder>
</Request>
";


$header= "POST /authorize/ HTTP/1.0\r\n"; // HTTP/1.1 should work fine also
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-type: application/PTI40\r\n";
$header.= "Content-length: " .strlen($post_string) . "\r\n";
$header.= "Content-transfer-encoding: text\r\n";
$header.= "Request-number: 1\r\n";
$header.= "Document-type: Request\r\n";
$header.= "Interface-Version: Test 1.4\r\n";
$header.= "Connection: close \r\n\r\n"; // Must have two CR/LF's here
$header.= $post_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_HEADER, false); // You are providing a header manually so turn off auto header generation
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
// The following two options are necessary to properly set up SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}

// use XML Parser on $data, and your set!

$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);

$parsedResArr = parseXmlResponse($vals);
echo '<pre>' , print_r($parsedResArr) , '<pre>';


function parseXmlResponse($xmlResponse)
{
$newResArr = array();
foreach($xmlResponse as $val)
{
$tagval=$val['tag'];
if(($val['tag']!='Response') && ($val['tag']!='NewOrderResp')) {
if (isset($val['value'])) {
$newResArr[$tagval]=$val['value'];
}
else{
$newResArr[$tagval]='';
}
}
}

return $newResArr;
}


?>

Thursday, May 28, 2009

 

Paste Word in TinyMCE


<script language="javascript" src="js/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">


tinyMCE.init({
theme : "advanced",
mode : "exact",
elements : "profile",
plugins : "paste",
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect|,forecolor,backcolor",
theme_advanced_buttons3_add : "pastetext,pasteword,selectall",
paste_create_paragraphs : false,
paste_create_linebreaks : false,
paste_use_dialog : true,
paste_auto_cleanup_on_paste : true,
paste_convert_middot_lists : false,
paste_unindented_list_class : "unindentedList",
paste_convert_headers_to_strong : true,
paste_insert_word_content_callback : "convertWord"
});

function convertWord(type, content) {
switch (type) {
// Gets executed before the built in logic performes it's cleanups
case "before":
// do nothing
break;

// Gets executed after the built in logic performes it's cleanups
case "after":
content = content.replace(/<(!--)([\s\S]*)(--)>/gi, "");
break;
}

return content;
}

</script>


Wednesday, May 27, 2009

 

Obtain Email Addresses in a string

preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i",  trim(substr($line, 16)), $matches);
print_r(implode("\n", $matches[0]));

Archives

June 2008   July 2008   August 2008   September 2008   October 2008   November 2008   December 2008   January 2009   February 2009   March 2009   May 2009   July 2009   September 2009   October 2009   January 2010   WEC 44 live stream   UFC 106 live stream

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]