<?php
$filename = str_replace(“.”,date(‘-Y-M-d-D-H-i-s.’),$_FILES[‘upload’][‘name’]);
echo “<table border=’1′>”;
if (($handle = fopen($filename, “r”)) !== FALSE) {
while (($data = fgetcsv($handle, 1000, “,”)) !== FALSE){ ?>
<tr><?php foreach($data as $values) {?><td > <?php echo $values ?></td><?php } ?></tr>
<?php }
}
echo “</table>”;
?>
Tag Archives: PHP
Why PHP
- PHP is open source
- PHP is free to download and use
- PHP is compatible with platform like Linux ,Windows etc
- PHP can be used with the servers like Apache,IIS etc .
- PHP suports databses like Mysql,Oracle etc
PHP
PHP is a server side scripting language used in web development to cerate dynamic web pages and can be embedded into HTML codes .The web server with php processor module interprets the code and geneate the web pages as per the given code .
PHP stands for PHP Hypertext Preprocessor (A recursive acronym) .Earlier it was known as personnel home pages .
PHP is an open source software and its free to download and use .
It supports many databases like MySql,Oracle etc…
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).
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_URL
Remove all unwanterd characters form a URL
Example
======
<?php
$url=”http://www.phpcoåødez.com”;
echo filter_var($url, FILTER_SANITIZE_URL);
?>
Output
=====
FILTER_VALIDATE_BOOLEAN
Return TRUE for “true”, “1”, “on” and “yes”, FALSE for “0”,”false”, “off”, “no”, and “”, NULL otherwise
Example
======
<?php
echo filter_var(“Yes”, FILTER_VALIDATE_BOOLEAN);
?>
Output
=====
1
FILTER_UNSAFE_RAW
Removes characters that is potentially harmful for your application
Example
======
<?php
echo filter_var(“PHPCodez'”, FILTER_UNSAFE_RAW);
?>
Output
=====
PHPCodez’