Example:
Code:
<html>
<head>
<script type="text/javascript">
function changecolor(color_code)
{
document.bgColor=color_code;
}
</script>
</head>
<body>
</body>
</html>
Example:
Code:
<html>
<head>
<script type="text/javascript">
function changecolor(color_code)
{
document.bgColor=color_code;
}
</script>
</head>
<body>
</body>
</html>
Example:
Code:
<html>
<body>
<script type="text/javascript">
{
var txt="Shane Watson";
document.write(txt.replace("Watson","Harwood"));
}
</script>
</body>
</html>
Output:
Shane Harwood
Example:
Code:
<html>
<body>
<script type="text/javascript">
{
var txt="JOHN";
document.write(txt.toLowerCase());
}
</script>
</body>
</html>
Output:
john
Example:
Code:
<html>
<body>
<script type="text/javascript">
{
var txt="John";
document.write(txt.toUpperCase());
}
</script>
</body>
</html>
Output:
JOHN
Example:
Code:
<html>
<body>
<script type="text/javascript">
{
var txt="John";
document.write(txt.length);
}
</script>
</body>
</html>
Output:
4
Example:
Code:
var a=1;
for (a=1;a<=10;a++)
{
document.write("The number is " + a);
document.write("
");
}
Output:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10
var a=11;
if (a>10)
{
document.write(a);
}
Output:
11
You can create JavaScript variables with the var keyword, as follows:
<script type="text/javascript"> var a; var name; </script>
After the declaration , the variables are empty (they have no values).
you can also assign values to the variables when you declare them,as follows:
<script type="text/javascript"> var a=10; var name="John"; </script>
Note: When you assign a text value to a variable, use quotes around the value.
Example:
Code:
<html>
<body>
<script type="text/javascript">
var a;
a=10+10;
document.write(a);
document.write("");
a="10"+"10";
document.write(a);
document.write("");
a=10+"10";
document.write(a);
document.write("");
a="10"+10;
document.write(a);
document.write("");
</script>
</body>
</html>
Output:
20
1010
1010
1010
Note: If you add a number and a string, the result will be a string.
<html>
<body>
<script type="text/javascript">
{
document.write("<h1>This is a heading</h1>");
document.write("<p>Hello.</p>");
document.write("<p>World.</p>");
}
</script>
</body>
</html>
OutPut:
Hello.
World.
Example:
Code:
<html>
<head>
<script type="text/javascript">
function displayDate()
{
document.getElementById("idname").innerHTML=Date();
}
</script>
</head>
<body>
<h1>The First Page</h1>
<p id="idname">This is a first paragraph.</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>
This is a first paragraph.
The web is stateless. But in ASP.NET, the state of a page is maintained in the in the page itself automatically. How? The values are encrypted and saved in hidden controls. this is done automatically by the ASP.NET. This can be switched off / on for a single control
It can be 0 to as many.
try must be followed by catch or finally.
ex:
1)0 catch statement
try
{
}
finally
{
}
2) any number
try
{
}
catch
{
}
catch
{
}
finally
{
}
in your CSS, you can specify the border property for linked images:
a img { border: none ; }
However, note that removing the border that indicates an image is a link makes it harder for users to distinguish quickly and easily which images on a web page are clickable.
This function writes a string to a file.
Syntax: file_put_contents(file,data,mode,context)
Description:
The Parameter “file” is Required. It Specifies the file to write to. If the file does not exist, this function will create one.
The second Parameter “data” is Required. The data to write to the file. Can be a string, an array or a data stream.
The third Parameter “mode” is Optional.It Specifies how to open/write to the file. Possible values:
FILE_USE_INCLUDE_PATH
FILE_APPEND
LOCK_EX
The third Parameter “context” is Optional. It Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream.
This function returns the number of character written into the file on success, or FALSE on failure.
Example:
Code:
echo file_put_contents("test.txt","Php code is executed on the server.");
Output:
35
This function returns the last access time of the specified file.
Syntax: fileatime(filename)
Description:
The Parameter filename is Required. It Specifies the file to check.
This function returns the last access time as a Unix timestamp on success, FALSE on failure.
Example:
Code:
echo fileatime("test.txt");
echo "";
echo "Last visit: ".date("F d Y H:i:s.",fileatime("test.txt"));
Output:
1307162313
Last visit: June 04 2011 04:38:33.
The function reads a file into a string.
Syntax: file_get_contents(path,include_path,context,start,max_length)
Description:
The first parameter “path” is Required. It specifies the file to read.
The second parameter include_path is Optional. It Set this parameter to ’1′ if you want to search for the file in the include_path (in php.ini) as well.
The third parameter “context” is Optional. It specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream. Can be skipped by using NULL.
The fourth parameter “start” is Optional. It Specifies where in the file to start reading. This parameter was added in PHP 5.1.
The fifth parameter “max_length” is Optional. It specifies how many bytes to read. This parameter was added in PHP 5.1.
Example:
Code:
echo file_get_contents("test.txt");
Output:
PHP is an interpreted language.
The is_readable() function checks whether the specified file is readable.
Syntax: is_readable(file)
Description:
The parameter “file” is Required. It specifies the file to check.
This function returns TRUE if the file is readable.
Example:
Code:
$file = "test.txt";
if(is_readable($file))
echo ("$file is readable");
}
else
{
echo ("$file is not readable");
}
Output:
This function returns the size of the specified file.
Syntax: filesize(filename)
Description:
The argument “filename” is Required. It specifies the file to check.
This function returns the file size in bytes on success or FALSE on failure.
Example:
Code:
echo filesize("test.txt");
Output:
34
This function renames a file or directory.
Syntax: rename(oldname,newname,context)
The first Parameter “oldname” is Required. It Specifies the file or directory to be renamed.
The second Parameter “newname” is Required.It Specifies the new name of the file or directory.
The third Parameter “context” is Optional.It Specifies the context of the file handle. Context is a set of options that can modify the behavior of a stream.
Description:
This function returns TRUE on success, or FALSE on failure.
Example:
Code:
rename("test.txt","test1.txt");
Explanation:
The above code rename the test.txt to test1.txt.
© PHPInterviewQuestion.com 2009 - 2012