Archive

Archive for the ‘php’ Category

Php to Excel

August 17, 2007 1 comment

This is one sweet code to export your variables and pass it on to a downloadable excel file. As of now i am working on an resume maintenance project and that needs this aspect. I googled for the simplest and efficient code.

I use a wamp localhost and faced warnings with all classes and codes that use the fopen(xls://FILENAME) format. This particular code was so cool enough to not read and open any existing file but just provide a  new file that you’ll name at runtime and download.

Its  more like writing the file on flyby!!

If you were one among those who googled for excel to php/php to excel/php write excel files/write excel files in php  and came here, trust me its a standalone simple code below. Just copy paste and it will start working.

<?php
$line1=”ID\tProduct\tColor\tSales\t”;
$line2=”1\tPrinter\tGrey\t13\t”;
$line3=”2\tCD\tBlue\t15\t”;
$line4=”3\tDVD\tRed\t7\t”;
$line5=”4\tMonitor\tGreen\t4\t”;
$line6=”5\tTelephone\tBlack\t2\t”;
$data=”$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n”;

header(“Content-type: application/x-msdownload”);
header(“Content-Disposition: attachment; filename=extraction.xls”);
header(“Pragma: no-cache”);
header(“Expires: 0″);
print “$header\n$data”;

?>

The code is pretty self explanatory with /t for column break and \n for line break.

Cya
Madan

Categories: php

Php controlled program

Assume that you have a C exe file or just any exe for that matter. In our specific example say we have generated the “Airtel tune.exe” in c . Now you create a php file having one “Submit” button.

And once you click the “submit button” you need to execute airtel tune.exe . This can be established by the following code.

<?php
System(“location of file” “arguments if any”) ;
?>

Example:

<?php
System(“a:/airteltune.exe”) ;
?>

Your Submit button can call the php file which has the above code and thus initiate the execution of this exe file. This is true for any program. You may even control your parallel port from php by writing appropriate c codes which can be called form the php file itself.

Madan

Categories: php

Send a mail using a PHP code??

November 3, 2006 1 comment

Well i was jus working on a bit of php for my site and i liked the code part of it. Just not to forget i thought i’l put those esential chunk of code here so that i can always get them back whenever i want.

well you call it tutorial or anything this is just a code to send a mail to any mailbox form your personalised form like this one on the site that i’m developing.

Well it is always better to start with an example. Click here to see one

Well to simplify all the from address,to address,message let me just give u the single line code in php to send a mail. it goes this way as below


<?php
mail(“yourmail@yourmail.com”, “subject”, “this is the actual mesasge that’s sent”,”header”);
?>


The above code will send a mail to the given address but will send the address of sender as “anonymous@xxx.yyy.com” the following code below will asign those values to make it look as if it came from a particular email id.

<?php
$email=”madankumar.t@gmail.com”; (to address)
$message2 .= “
This is the actual message that’l be sent
“;
$headers2 .= “From: madan@invobot.com\n”;(from address to be displayed ***)
$sub2.=”This will be the subject”;
?>
<?php
mail($email, $sub2, $message2, $headers2);
?>


When you copy the above as such the quotes donot come properly!! u must manually replace all properly , better download from the link below!! 

You find it difficult to copy paste and test? well download it hereWell now the fun part. Is your college principals email id something like “xxxx@college.com“??? and your class teachers’s E-mail something like “yyyy@college.com“??? heya, why not send a mail to your proff from the principal? don mind uh.

cheers
Madan

Note: Any suggestions here is just an idea for fun. no legal issues can be brought upon me for anything that is suggested in this site. Thankyou :)

Categories: php, web
Follow

Get every new post delivered to your Inbox.