> 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