Tag Archives: PHP

DOM

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.[1] Aspects of the DOM (such as its “Elements”) may be addressed and manipulated within the syntax of the programming language in use. The public interface of a DOM is specified in its application programming interface (API).

Following are the valid DOM save methods

A. save()
B. saveXML()
C. saveHTML()
D. saveHTMLFile()

Send mail with attachment – PHP

<?php

class sendMail{

function send($mailto, $subject,$message , $filename, $path, $from_mail, $from_name, $replyto ) {

if(!empty($filename)) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, “r”);
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$name = basename($file);
}

$uid = md5(uniqid(time()));

$header = “From: “.$from_name.” <“.$from_mail.”>rn”;
$header .= “Reply-To: “.$replyto.”rn”;
$header .= “MIME-Version: 1.0rn”;
$header .= “Content-Type: multipart/mixed; boundary=””.$uid.””rnrn”;
$header .= “This is a multi-part message in MIME format.rn”;
$header .= “–“.$uid.”rn”;
$header .= “Content-type: text/html; charset=iso-8859-1n”;
$header .= “Content-Transfer-Encoding: 7bitrnrn”;
$header .= $message.”rnrn”;
$header .= “–“.$uid.”rn”;

if(!empty($filename)) {
$header .= “Content-Type: application/octet-stream; name=””.$filename.””rn”; // use different content types here
$header .= “Content-Transfer-Encoding: base64rn”;
$header .= “Content-Disposition: attachment; filename=””.$filename.””rnrn”;
$header .= $content.”rnrn”;
$header .= “–“.$uid.”–“;
}

if (mail($mailto, $subject, “”, $header)) {
return 1;
} else {
return 0;
}
}

}

 

$mail = new sendMail();

$mail->send(“info@phpcodez.com”,”Test”,”Test” , “image1.jpg”,”../images/”,”newsletter@phpcodez.com”,”PHPCodez”,”newsletter@phpcodez.com”);

?>

var_export

It prints parsable string representation of a variable

Example
======

<?php
echo “<pre>”;
$array = array(“php”,”codez”, array(“1”, “1”, “7”),1,2);
var_export($array);
?>

Output
=====
array (
0 => ‘php’,
1 => ‘codez’,
2 =>
array (
0 => ‘1’,
1 => ‘1’,
2 => ‘7’,
),
3 => 1,
4 => 2,
)

var_dump

It displays structured information about one or more expressions .

Example
======

<?php
echo “<pre>”;
$array = array(“php”,”codez”, array(“1”, “1”, “7”),1,2);
var_dump($array);
?>

Output
=====
array(5) {
[0]=>
string(3) “php”
[1]=>
string(5) “codez”
[2]=>
array(3) {
[0]=>
string(1) “1”
[1]=>
string(1) “1”
[2]=>
string(1) “7”
}
[3]=>
int(1)
[4]=>
int(2)
}

FILTER_SANITIZE_NUMBER_FLOAT

Remove all illegal characters from a float number

Example
======

<?php
echo filter_var(“1-7php+5.4Codez”, FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
?>

Output
=====

1-7+5.4

Possible flags:

FILTER_FLAG_ALLOW_SCIENTIFIC – Separate fraction with e and E)

FILTER_FLAG_ALLOW_FRACTION – Separate fraction with “.”
FILTER_FLAG_ALLOW_THOUSAND – Separate fraction with “,”