Example #1 error_reporting() examples

<?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE
// This is the default value set in php.ini
error_reporting(E_ALL ^ E_NOTICE);

// Report all PHP errors (see changelog)
error_reporting(E_ALL);

// Report all PHP errors
error_reporting(-1);

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

, , ,

sameple 1: select * from table where datediff(createdate, NOW())=’0′;”);

sameple 2: select * from table where createdate>subDate(NOW(), ’1′);

 

,

#!/bin/bash
date=`date +%d`;
tar -czvf ~/backup/htmlbackup_$date.tar.gz /var/www/html/>/dev/null
curl -T ~/backup/htmlbackup_$date.tar.gz ftp://user:password@mydomain.com

<?php

function processing_time($START=false)
{
$an = 4; // How much digit return after point

if(!$START) return time() + microtime();
$END = time() + microtime();
return round($END – $START, $an);
}

?>

<?php
require_once “./pageload.php”;
$START = processing_time();

#####some code here########

$RESULT = processing_time($START);
echo $RESULT;

?>

,

<script type=”text/javascript”>
function numericonly(e){
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
//alert(‘Character was ‘ + character);
//alert(code);
//if (code == 8) return true;
var AllowRegex = /^[\b0-9.]$/;
if (AllowRegex.test(character)) return true;
return false;
}
function typetextandnumonly(e){
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
var AllowRegex = /^[a-zA-Z0-9]$/;
if (AllowRegex.test(character)) return true;
return false;
}

</script>

 

<input name=”password” type=”password” id=”password” size=”50″ maxlength=”50″ value=”" onkeypress=”return typetextandnumonly(event);” />

, ,
  1. $date = date(“Y-m-d”);
  2. $date = strtotime(date(“Y-m-d”, strtotime($date)) . ” +12 month”);
  3. $date = date(“Y-m-d”,$date);
  4. echo $date;
  5. Other examples
  6. $date = strtotime(date(“Y-m-d”, strtotime($date)) . ” +1 day”);
  7. $date = strtotime(date(“Y-m-d”, strtotime($date)) . ” +1 week”);
  8. $date = strtotime(date(“Y-m-d”, strtotime($date)) . ” +2 week”);
  9. $date = strtotime(date(“Y-m-d”, strtotime($date)) . ” +1 month”);
  10. $date = strtotime(date(“Y-m-d”, strtotime($date)) . ” +30 days”);

Example 1

<?php

$notice_text = “This is a multi-part message in MIME format.”;
$plain_text = “This is a plain text email.\r\nIt is very cool.”;
$html_text = “<html><body>This is an <b style=’color:purple’>HTML</b> text email.\r\nIt is very cool.</body></html>”;

$semi_rand = md5(time());
$mime_boundary = “==MULTIPART_BOUNDARY_$semi_rand”;
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);

$to = ‘abc@abc.com’;
$bcc = “You <you@you.com>, Them <them@them.com>”;
$from = “Me.com <me@me.com>”;
$subject = “My Email”;

$body = “$notice_text

–$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

$plain_text

–$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

$html_text

–$mime_boundary–”;

if (@mail($to, $subject, $body,
“From: ” . $from . “\n” .
“bcc: ” . $bcc . “\n” .
“MIME-Version: 1.0\n” .
“Content-Type: multipart/alternative;\n” .
” boundary=” . $mime_boundary_header))
echo “Email sent successfully.”;
else
echo “Email NOT sent successfully!”;
?>

http://www.tek-tips.com/faqs.cfm?fid=2681

Example 2

Headers

MIME-Version: 1.0

From: Foo <foo@bar.com>

Subject: Test mail

Content-Type: multipart/alternative;boundary=np4f377521487cd

Body

This is a MIME encoded message.

 

–np4f377521487cd

Content-type: text/plain;charset=utf-8

 

This is the text/plain version.

 

–np4f377521487cd

Content-type: text/html;charset=utf-8

 

This is the <b>text/html</b> version.

 

–np4f377521487cd–


<?php

 

$boundary = uniqid(‘np’);

 

 

$headers = “MIME-Version: 1.0\r\n”;

$headers .= “From: Foo <foo@bar.com>\r\n”;

$headers .= “Subject: Test mail\r\n”;

$headers .= “Content-Type: multipart/alternative;boundary=” . $boundary . “\r\n”;

 

 

$message = “This is a MIME encoded message.”;

 

$message .= “\r\n\r\n–” . $boundary . “\r\n”;

$message .= “Content-type: text/plain;charset=utf-8\r\n\r\n”;

$message .= “This is the text/plain version.”;

 

$message .= “\r\n\r\n–” . $boundary . “\r\n”;

$message .= “Content-type: text/html;charset=utf-8\r\n\r\n”;

$message .= “This is the <b>text/html</b> version.”;

 

$message .= “\r\n\r\n–” . $boundary . “–”;

 

//mail(‘bar@foo.com’, ‘Test mail’, $message, $headers);

 

?>

 

http://krijnhoetmer.nl/stuff/php/html-plain-text-mail/
, , ,

Access parent windows within iframe using jQuery.

e.g.

<script type=”text/javascript”>

p=window.parent;

p.$(‘#select2′).append(‘<option value=\”$matches[1],$matches[2]\”>&lt; $matches[1] &gt; $matches[2]</option>’);

</script>

, ,

In jQuery, you can get elements with CSS class name and id easily.

For example,

1. ID: #id

  • $(‘#idA’) – selects all elements that have an id of ‘idA’, regardless of its tag name.
  • $(‘div#idA’) – selects all div elements that has an id of ‘idA’.

2. Class: .classname

  • $(‘.classA’) – selects all elements that have an class name of ‘classA’, regardless of its tag name.
  • $(‘div.classA’) – selects all div elements that has an class name of ‘classA’.

3. Class: [name="value"]

  • $(‘div[name^="nameA"]’) – selects all elements that have an name of ‘nameA’, regardless of its tag name.
  • e.g. [name*="value"], [name~="value"], [name$="value"]

3. Change attr: $(‘#idA’).attr()

  • $(‘#idA’).attr(‘src’, ‘value) – change value of attribute that have an idof ‘idA’, regardless of its tag name.

Full Example

<html>
<head>
<title>jQuery Get element with class name and id</title>

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

</head>

<script type="text/javascript">

$(document).ready(function(){

    var $element = $('.classABC').html();
    alert($element);

    var $element = $('#idABC').html();
    alert($element);

});

</script>
<body>

<h1>jQuery Get element with class name and id</h1>

	<div class="classABC">
		This is belong to 'div'
	</div>

	<div id="idABC">
		This is belong to 'div id="idABC"'
	</div>

</body>
</html>
http://www.mkyong.com/jquery/jquery-how-to-get-element-with-css-class-name-and-id/
,

The ENUM Type

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.

An enumeration value must be a quoted string literal; it may not be an expression, even one that evaluates to a string value. For example, you can create a table with an ENUM column like this:

CREATE TABLE sizes (
    name ENUM('small', 'medium', 'large')
);

The SET Type

SET is a string object that can have zero or more values, each of which must be chosen from a list of permitted values specified when the table is created. SET column values that consist of multiple set members are specified with members separated by commas (“,”). A consequence of this is that SET member values should not themselves contain commas.

For example, a column specified as SET('one', 'two') NOT NULL can have any of these values:

''
'one'
'two'
'one,two'

SET can have a maximum of 64 different members.

 

ENUM and SET Constraints

ENUM and SET columns provide an efficient way to define columns that can contain only a given set of values. SeeSection 10.4.4, “The ENUM Type”, and Section 10.4.5, “The SET Type”. However, in MySQL 4.1 and earlier, ENUMand SET columns do not provide true constraints on entry of invalid data:

  • ENUM columns always have a default value. If you specify no default value, then it is NULL for columns that can have NULL, otherwise it is the first enumeration value in the column definition.
  • If you insert an incorrect value into an ENUM column or if you force a value into an ENUM column with IGNORE, it is set to the reserved enumeration value of 0, which is displayed as an empty string in string context.
  • If you insert an incorrect value into a SET column, the incorrect value is ignored. For example, if the column can contain the values 'a''b', and 'c', an attempt to assign 'a,x,b,y' results in a value of 'a,b'.
, ,