> Online tutorial

75% discount Hosting plan sale in Hostgator

75% discount Hosting plan sale in Hostgator

HostGator is one of the world's top 10 largest web hosting companies and offers the Black friday offer today.
Offer In Hostgator

Hostgator is offering 1 hour flash sale on Black friday, and you can grab hosting for as low as $1.24/month.
Discount: Various discount from Black friday to Cyber monday.
Start date: Today
End date: December 2nd


Click To Get

PHP interview Question with answer

PHP interview Question with answer

1)<?php
$varA=one;
$varB=&$varA;
$varA=two;
print $varB;
?>

Output:
2

It is result is Two because $varB holds the reference of $varA value an dboth $varA and $varB poin the same value.

2)<?php
$num1=6;
$num2=5;
$val=(num1>$num2)?$num1:$num2;
echo "Greatest of no".$val;num2;
?>

Output:
6
It is greatest of two number in the given number.

3)what is print_r()?

The print_r() is used to print out the entire content of array.
<?php
$fruit=array("orange","apple","mango");
print_r($fruit);
?>

4)What happened below code
<?php
print "type(152).gettype(152)."\n";
?>

Answer:

it is return the 152 as an Integer value.gettype() is used to get the datatype.

5)How do find the Ip address of remote machine?

Answer:

<?php
echo "your ip address is ".$SERVER['REMOTE_ADDR'];
?>

6)<?php
echo ucfirst("helloworld");
?>
what happened in this code?

Answer:

It is return the output Hello world.the ucfirst() is used to convert the first character in to Uppercase.

7)Difference between include() and require()?

In include() function if can't include the file it is generate error but continue the execution of program but require() function if can't include the file it is generate fatal error in script.

8)How destroy the session in PHP?

In session we are using unset() or session_destroy() function which is used to destroy the session in PHP.

9)What is use of explode() in PHP?
explode() function is used to convert string into array.

10)How do connect PHP with Mysql query?

$mysql_connect("address","username","password")

How do Upload File using PHP

How do Upload File using PHP

In PHP we are using two file which used upload file in the server.First one Html file and another one is PHP file .

In the Html file we are going get file content and PHP file we are process it and Upload into Particular file path.

Coding

In the coding section we are show First html file.In the html file we are going to get file and sent to php file using POST method.Here code for HTML file.


Upload.html:

1)In the form enctype/form data encding when submitting to the server.


<html>
<body>
<form enctype="multipart/formdata" action="saveupload.php" method="post">
<input type="file" name="fileToUpload">
<input type="submit" value="UploadFile">
</form>
</body>
</html>

saveupload.php:


1)$_FILES["file"]["name"] it is used get the name of file
2)$_FILES["file"]["type"] it is used to get type of file  
3)$_FILES["file"]["size"]  it is used to get size of file 
4)$_FILES["file"]["tmp_name"]  it is give tmp name of file which is ued to store the file in folder.


<?php

echo "<table border=\"1\">";
echo "<tr><td>Client Filename: </td>

   <td>" . $_FILES["file"]["name"] . "</td></tr>";

echo "<tr><td>File Type: </td>
   <td>" . $_FILES["file"]["type"] . "</td></tr>";
echo "<tr><td>File Size: </td>
   <td>" . ($_FILES["file"]["size"] / 1024) . " Kb</td></tr>";
echo "<tr><td>Name of Temp File: </td>
   <td>" . $_FILES["file"]["tmp_name"] . "</td></tr>";
echo "</table>";

move_uploaded_file($_FILES["file"]["tmp_name"], "C:/upload/" . $_FILES["file"]["name"]);

?>

move_uploaded_file(dest_file,source_file)

Here Upload is folder we can create in you local computer it is save the file. 

change button color in javascript

change button color in javascript

In the program we will show you How do change button color using javascript .In javascript we are using onmouseover it is used to record mouse move.


Source code




<html>
<head>
<script type="text/javascript">
function changeColor(color)
{
document.getElementById('MyButton').style.background=color;
}
</script>
</head>
<body>
<p>Move mouse over the color string</p>
<table width="60%">
<tr>
<td bgcolor='red' onmouseover="changeColor('red')">RED</td>

<td bgcolor='yellow' onmouseover="changeColor('yellow')">YELLOW</td>

<td bgcolor='aqua' onmouseover="changeColor('aqua')">AQUA</td>
</tr>
</table>
<form>
<input id="MyButton" type="button" value='changing color of buttons'>
</form>
</body>
</html>

How do search word in string using javascript


How do search word in string using javascript


In program we will show How do get word from given string using java script.When you are using search keyword it is searching word in the given string if it is found then return 0 otherwise not return any value.

Program


<html>
<head>
<script type="text/javascript">
function test()
{
document.write("The given String is");
document.write("<em>"+str+"</em>");
var i=str.search(/like/);
return i;
}
</script>
</head>
<body>
<h3>
<script type="text/javascript">
var index=test("I like programming");
if(index>0)
document.write("The match is found"+"<em>"+"like"+"<em>");
else
document.write("The match is not found");
</script>
</h3>
</body>
</html>

Output

The given String is
I like programmingThe match is foundlike



How do get server date using PHP

How do get server date using PHP

In this program i will show you how do get server date and time using PHP.In PHP getdate() function is used to get date in server.

Program

<?php
$time = getdate();
$date = $time['day'];
$month = $time['month'];
$year = $time['year'];
$hour = $time['hours'];
$min = $time['minutes'];
$sec = $time['seconds'];

$current_date = "$date/$month/$year == $hour:$min:$sec";

echo "$current_date";

?>


Output:



How do get month using javascript

How do Get month using javascript

In the java script we can using getMonth() function which is used to get current month.

Program



<html>
<body>
<script type="text/javascript">
d=new Date();
ch=d.getMonth();
document.write(ch);
</script>
</body>
<html>
Output:


In this program The program will return only numeric value if it is 2 then month is march so you can using this is coding you can find current month.

Pop up box in javascript

Pop up box in java script

In this below coding is used to show How do create popup box using javascript.
Alert box:In this type of pop up box some message will be displayed
confirm box:In this type of popup box in which message about confimation will be displayed
Prompt boxIn is a type of popup box which display text window in which user can enter something Hence it has two buttons OK or cancel




Program


<html>
<body>
<script type="text/javascript">
if(confirm("do you agrred?"))
alert("You have agreed");
else
input_text=prompt("Enter some string here," ");
alert("hi"+input_text);
</script>
</body>
</html>





make image using php

make image using php

In this program we will create image using php.In the imagecreate is used to create the image space.


<?php
header("Content-Type: image/png");

$im = @imagecreate(500, 120)

or die("Cannot Initialize new GD image stream");

$background_color = imagecolorallocate($im, 0, 0, 0);

$text_color = imagecolorallocate($im, 233, 14, 91);

imagestring($im, 1, 10, 10, "Online tutorial", $text_color);

imagepng($im);

imagedestroy($im);

?>
Output

generate random in php


generate random in php

In this program is used generate random number in PHP.we are using rand() used to generate random number in PHP.


<?php
echo rand() . "\n";
echo rand(10,4);
?>





Upload file using PHP

Upload file using PHP

HTML Coding

In this example .i will show How upload file using PHP.we are two program here.one is HTM and PHP program.

In the HTML file get the file and send to the PHP program using POST method.


<html>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
Select the file to upload<input name="upload" type="file" />
</form>
</body>
</html>

PHP Coding


<?php
$uploadddr='upload/';
$uploadfile=$uploaddr.basename($_FILE[''file']['name']);
if(move_uploaded_file($_FILE['file']['tmp_name'].$uploadfile))
{
echo "file is valid";
}
else
{
echo "file uploading failed";
}?>


PHP Program Explaination:

In the PHP program will get the file stored in file called upload.You must create upload folder in your Computer.

get Http vs Https in php

get Http vs Https in php

In this post. I will show you How do know your server protocol that is Http or https using PHP.
Coding



<?php

if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'
    || $_SERVER['SERVER_PORT'] == 443) {

  // HTTPS
echo 'https';
} else {

echo 'http';  // HTTP

}
?>

Output:

Getting image width and height using PHP

Getting image width and height using PHP

In Coding we are getting size of image using function getimagesize. it is get width and height of given object.


Coding


<?php

  list($width, $height, $type, $attr) = getimagesize("C:\wamp\www\Batista.jpg");

  echo "Image width <br/>" . $width."<br/>";
  echo "Image height <br/>" . $height."<br/>";
  echo "Image type <br/>" . $type."<br/>";
  echo "Attribute <br/>" . $attr."<br/>";

?>

Output





Get ip address using php

Get ip address using php

This tutorial i will show you get the IP(Internet Protocol)Address of proxy server.

Coding


<?php
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
     $ip=$_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
     $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
     $ip=$_SERVER['REMOTE_ADDR'];
echo $ip;
}
?>

Program Explaination:

In this coding the REMOTE_ADDR will finding IP address of proxy server.

Output:




How do finding metatag using PHP

How do finding metatag using PHP:
This tutorial i will show  how do find the metatag of website using PHP. They function called get_meta_tags Which is used to get information of meta tag in the website.


Coding


<?php $tags = get_meta_tags("http://www.w3schools.com"); ?>


<h2>Author</h2>

<?php echo $tags['author']; ?> <br/>      // name 

<h2>Keywords</h2>

<?php echo $tags['keywords']; ?>   </br>  // php documentation

<h2>Description </h2>

<?php echo $tags['description']; ?> </br> // a php manual




Program Explain:


In this Program you finding the meta tag in the website.here  get_meta_tags which used get metatag information you can specific any site here.s

Output:

compare two number without using relational operator in c

#include<stdio.h>
#include<conio.h>
int main () {
{
int a,b;
printf ( "enter the two values u like to compare\n");
scanf (" %d %d",&a,&b);

if (!(a ^ b))

// ^ is Xor operator.
Xor operator function below


valuesvlauesOutput
000
011
101
110


printf ("both are equal\n");
else
printf ("both are not equal\n");
}

Output
Enter the value
10
15
Both are not equals

HTML tag



tag nameDefinitionSyntax
<a> An anchor text which it used to create hyperlinks in HTML. <a href='enter the website name'>Name of site</a>
<b>Which is used to blod the text in HTML.<b>Enter the header name</b>
<ul> Un ordered list which is list the item in HTML.list is nothing but collection of data. <ul type='type of character'>
<ol>ordered list which is orderly list the item in HTML.list is nothing but collection of data. <ol type='disc/square/circle'>
<font> Which is used specific the particular in text we can using this tag in HTML. <font>Enter the text</font>
<basefont >only used in IE not worked in Mozila and chrome and other browser.
<table> table tag which used to create the table in HTML. <table>
<tr>Table row which is used create the table row.

Marquee is used to scroll the text.
<br> BR is used providing new line at the end of paragraph.
<title>
Title tag is used give the title to webpage.
<body>Body tag is used to display data in client browser.
<h1> h1 is used to biggest heading 1
<h2>h2 is used to biggest heading 2
<h3>h3 is used to biggest heading 3


<h4>h4 is used to biggest heading 4
<h5>h5 is used to biggest heading 5
<h6>h6 is used to biggest heading 6
<p>The tag is used in paragraph.every end of paragraph we can put this tag.
<pre>The tag is used tp preserve the white space and lines in the text.
<div>This is tag is used to make the division of section in the html.
<i>It is used show text as italic.
<strong>It is used strong emphasized the text.
<strike>This is used the strike the text.
<center>This tag is used the center the text.

registration form in php


Registration form:
This is registration form in which data are entered by the user then it is goes to database for storing data.In this registration form we create four field and send data using form tag.
<html>
<body>
<form name="form1" action="signup2.php" method="post">
Name<input type='text' name='name'>
Email id<input type='text' name='email'>
Pass<input type='password' name='pass'>
Country<input type='text' name='country'>
<input type='submit' name='submit' value='Insert'>
</form>
</body>
</html>

Storing data in database:

In this program we are create database connectivity storing data which entered by user in registration form.In this data are useful processing the query.

<?php
$conn=mysql_connect('localhost','root','');
$db_name='temp';
mysql_select_db($db_name);
$name=$_POST['name'];
$email=$_POST['email'];
$pass=$_POST['pass'];
$country=$_POST['country'];
$insert=mysql_query("insert into tempv(name,email,pass,country)values('$name','$email','$pass','$country')");
?>

send emails using php

Registration form

We are create registration form which is important in data storing when the entered value in field the data are redirect value to corresponds method by using form tag.Now they store data in Mysql database for furthur processing on the data.

<html>
<body>
<div align='left'>
<table border='1'>

<form name='form1' action='post' method='reglog.php'>
//In which the HTML values will be redirected to reglog.php program using POST method is used


<table bgcolor='skyblue' border='1'>
<tr><td width='50'>Name:</td><td width='50'><input type='name' name='name' placeholder='Enter the Name'>
</td></tr>
<tr><td width='50'>Password:</td><td width='50'><input type='password' name='pass' placeholder='Enter the password'>
</td></tr>
<tr><td width='50'>Retype password:</td><td width='50'><input type='password' name='pass' placeholder='Retype Password'>
</td></tr>
<tr><td width='50'>Email id:</td><td width='50'><input type='text' name='email' placeholder='Enter the Email id'>
</td></tr>
<tr><td width='50'></td><td width='70'><input type='submit' value='Submit'>
</td></tr>
<tr>
</form>
</tr>
</table>
</div>
</body>
</html>


Mysql connectivity

Now we are going to create the database for storing data in verification process .using following MYSQL syntax to create database in MYSQL

Common Syntax
Create database
create database database_name;
Use database
use database_name;
create table query
create table tab_name(tab_name varchar(20),tab_name1 varchar(20),tab_name3 varchar(20),tab_name4 varchar(20),));


Sending mail in php:

Now we are create database connectivity for the program

<?php
$tbl_name=name of table;
// Random confirmation code
$confirm_code=md5(uniqid(rand()));
// values sent from form
mysql_select_db($db_name);
$name=$_POST['name'];
$pass=$_POST['pass'];
$repass=$_POST['repass'];
$email=$_POST['email'];
$insert=mysql_query("insert into table_name(name,pass,repass,email)values('$name','$pass','$repass','$email')");
if($result)
{
$to=$email;
$subject="Your confirmation link here";
$header="from: your name ";
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.yousiteaddress.com/confirmation.php?passkey=$confirm_code";
$sentmail = mail($to,$subject,$message,$header);
}
else
{
echo "Not found your email in our database";
}
if($sentmail)
{
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>

HTML list

HTML list
List is nothing but the collection of items or elements.There are two type of list are
ordered list,unordered list

UnOrdered List:

UnOrdered List is used for simply using listing the items but if we want the items in the sequence then ordered lists are used.

HTML Unordered List Example
    <html>
    <body>
    <b>Fruit List</b>
    <ul type='disc'>
    <li>Orange</li>
    <li>Apple</li>
    <li>Pine apple</li>
    </ul>
    <b>Sports List</b>
    <ul type='square'>
    <li>Cricket</li>
    <li>Foot Ball</li>
    <li>Hockey</li>
    </ul>
    <b>Country List</b>
    <ul type='circle'>
    <li>India</li>
    <li>Usa</li>
    <li>UK</li>
    </ul>
    </body>
    </html>

Output of Unordered List
  • Orange
  • Apple
  • Pine apple
Sports List
  • Cricket
  • Foot Ball
  • Hockey
Country List
  • India
  • Usa
  • UK
    Ordered List:
                  Ordered List is used for simply using listing the items but the follow some specific.we can use number the text using ol tag.
    Example

    <html>
    <body>
    <b>Fruit List</b>
    <ol type='1'>
    <li>Orange</li>
    <li>Apple</li>
    <li>Pine apple</li>
    </ol>
    <b>Sports List</b>
    <ol type='A'>
    <li>Cricket</li>
    <li>Foot Ball</li>
    <li>Hockey</li>
    </ol>
    <b>Country List</b>
    <ol type='i'>
    <li>India</li>
    <li>Usa</li>
    <li>UK</li>
    </ol>
    </body>
    </html>

    output

    1. Orange
    2. Apple
    3. Pine apple
    Sports List
    1. Cricket
    2. Foot Ball
    3. Hockey
    Country List
    1. India
    2. Usa
    3. UK