Tuesday, March 25, 2014

create a calandar using PHP

create a calandar using PHP


In this tutorial you will learn how to build your own web based calendar using PHP. This calendar is made you can use a plain text editing software such as Notepad.


calandar.php



<?php

$monthNames = Array("January", "February", "March", "April", "May", "June", "July", 

"August", "September", "October", "November", "December");

?>


First we need to check if we have set up our parameters already. If we have not, we set them to the current month and year. (For detailed explanation of date() function please refer to PHP Manual ).

<?php

if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");

if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");

?>


Lets also set the variables that we are going to use in our calandar:

<?php

$cMonth = $_REQUEST["month"];

$cYear = $_REQUEST["year"];



$prev_year = $cYear;

$next_year = $cYear;

$prev_month = $cMonth-1;

$next_month = $cMonth+1;



if ($prev_month == 0 ) {

 $prev_month = 12;

 $prev_year = $cYear - 1;

}

if ($next_month == 13 ) {

 $next_month = 1;

 $next_year = $cYear + 1;

}

?>

<table width="200">

<tr align="center">

<td bgcolor="#999999" style="color:#FFFFFF">

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>

<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>  </td>

</tr>

</table>

</td>

</tr>

<tr>

<td align="center">

<table width="100%" border="0" cellpadding="2" cellspacing="2">

<tr align="center">

<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>

</tr>

<tr>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>

<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>

</tr>


// because we don't want our dates to start from 0.

 

<?php 

$timestamp = mktime(0,0,0,$cMonth,1,$cYear);

$maxday = date("t",$timestamp);

$thismonth = getdate ($timestamp);

$startday = $thismonth['wday'];

for ($i=0; $i<($maxday+$startday); $i++) {

 if(($i % 7) == 0 ) echo "<tr>n";

 if($i < $startday) echo "<td></td>n";

 else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td>n";

 if(($i % 7) == 6 ) echo "</tr>n";

}

?>


// Now we add just the finishing touches of the html and we have finished the calendar.

</table>

</td>

</tr>

</table>
Read more....

Monday, March 24, 2014

PHP Interview Questions.


 PHP Interview Questions.

 As PHP language is in trend nowadays that’s why all web developing companies give priority to those candidates who are good in PHP language. These companies hire the desired candidates who have a good knowledge of HTML language as well as PHP language & ask them the following PHP Interview Questions.

Frequently Asked PHP Interview Questions

What is PHP?
PHP is an open source scripting language which is widely used nowadays. The full form of PHP is Hypertext Pre-processor.

What is a PHP File?
Those files which contain text, HTML, JavaScript code, and PHP code are known as PHP files. The default file extension of PHP files is “.php”.

What is the current version of PHP, Apache, MySQL?
The current version of PHP is php 5.1.2, the current version of Apache is Apache 2.1 and the current version of MySQL is MySQL 5.1.

What are the uses of PHP language?
The main uses of PHP language are following:-
1. PHP language is used to generate dynamic page content.
2. Through PHP language user can create, open, read, write, and close files on the server.
3. User can collect form data through PHP language.
4. You can send and receive cookies with the help of PHP language.
5. User can add, delete and modify data in your database through PHP language.

Why we use PHP over other languages?
We use PHP language over other languages beacuse PHP language runs on different platforms like Windows, Linux, Unix, Mac OS X, etc. It is also compatible on all servers like Apache, IIS, etc.

In PHP language, what does a special set of tags <?= and ?> do?
The use of special set of tags in PHP language is to display the output of the program directly to the browser.

What is the common difference b/w include and require in PHP language?
In PHP language the functions include and require are used to handle the failures in a program. The common diffrence between include and require in PHP language is that in case of include function, if the file of any program is not found by include() then it shows a warning to the user but side by side the execution of the script will continue. In case of require function in PHP language, if the file of any program is not found by the rquire() then it shows a fatal error to the user and also it halt the execution of the script.

Read more....

Saturday, March 8, 2014

pdf using php and fpdf

how can we generate a pdf using php and fpdf

What is FPDF?

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
FPDF has other advantages: high level functions. Here is a list of its main features:

1. download fpdf packeage .
2. pdfExample.php 


<?php
require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>


Header, footer, page break and image

<?php
require('fpdf.php');

class PDF extends FPDF
{
// Page header
function Header()
{
    // Logo
    $this->Image('logo.png',10,6,30);
    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(30,10,'Title',1,0,'C');
    // Line break
    $this->Ln(20);
}

// Page footer
function Footer()
{
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','I',8);
    // Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}

// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10,'Printing line number '.$i,0,1);
$pdf->Output();
?>

 

Cell

Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])


$pdf->Cell(20,10,'Title',1,1,'C');

SetFont

// Times regular 12
$pdf->SetFont('Times');
// Arial bold 14
$pdf->SetFont('Arial','B',14);
// Removes bold
$pdf->SetFont('');
// Times bold, italic and underlined 14
$pdf->SetFont('Times','BIU');

 

Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):
  • Courier (fixed-width)
  • Helvetica or Arial (synonymous; sans serif)
  • Times (serif)
  • Symbol (symbolic)
  • ZapfDingbats (symbolic)
It is also possible to pass an empty string. In that case, the current family is kept.
style
Font style. Possible values are (case insensitive):
  • empty string: regular
  • B: bold
  • I: italic
  • U: underline

 


Read more....
Related Posts Plugin for WordPress, Blogger...