Explode function in php

How to split a name using explode function?
1. Get the name in a variable
2. Specify the position from which you need to split the name.
3. If you need to split the name after an underscore, use “_”.
4. If you need to split the name after @, use “@”.

[php]

<?php

$name  = "john_abraham@gmail.com";
$pieces = explode("_", $name);
echo "firstname = $pieces[0]"."<br />";

$pieces = explode("@", $name);
echo "username = $pieces[0]";

?>

[/php]

Output will be displayed as:
firstname = john
username = john_abraham

TAGS:

IF Statement In PHP

[php]

<html>

<head>
<title>IF statements in PHP.</title>
</head>
<body>

<?php

$name = "Rose";

if ( $name == "Rose" )

echo "Your name is Rose!<br />";

else

echo "Welcome to my homepage!";
?>
</body>
</html>

[/php]

Output:

If the Given input is Rose,the output will be

Your name is Rose!

Else

Welcome to my homepage!

Switch Case in Java Script

[php]

<html>
<body>
<head>
<title>Switch Case </title>
</head>
<body>
<script type="text/javascript">
var d = new Date();
theDay=d.getDay();
switch (theDay)
{
case 5:
document.write("<b>Finally Friday</b>");
break;
case 6:
document.write("<b>Super Saturday</b>");
break;
case 0:
document.write("<b>Sleepy Sunday</b>");
break;
default:
document.write("<b>I’m really looking forward to this weekend!</b>");
}
</script>
</body>
</html>

[/php]

/*This JavaScript will generate a different greeting based on what day it is. Note that Sunday=0, Monday=1, Tuesday=2, etc.*/

Output:

I’m really looking forward to this weekend!

Java Script for Mouse Events

[php]

<html>
<head>
<script type="text/javascript">
function mouseOver()
{
document.getElementById("b1").src ="b_blue.gif";
}
function mouseOut()
{
document.getElementById("b1").src ="b_pink.gif";
}
</script>
</head>

<body>
<img border="0"   src="E:\pictures\baby.jpg" id="b1"
onmouseover="mouseOver()" onmouseout="mouseOut()" /></a>
</body>
</html>

[/php]

output:

The function mouseOver() causes the image to shift to “b_blue.gif”.

The function mouseOut() causes the image to shift to “b_pink.gif”.

To upload a file using php

Steps:

1. Create new html file and copy upload.html code and save it as upload.html.

2. Create new php file and copy uploader.php code and save it as uploader.php.

3. Run upload.html, then it will display the html data.

4. Click browse button and select any file or image and press upload button.

5. Then it will transfer that specific file or image to the created folder and display the output as file is uploaded.

upload.html:

[php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>upload</title>
</head>

<body>
<form enctype="multipart/form-data" method="post" action="uploader.php">
<input type="file" name="file" />
<input type="submit" name="submit" value="upload" />
</form>
</body>
</html>

[/php]

It displays the output as:


uploader.php
[php]</form><form action="uploader.php" method="post" enctype="multipart/form-data"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head><body>
<?php
if(isset($_REQUEST[‘submit’]))
{
$to="uploaded/".$_FILES[‘file’][‘name’];
move_uploaded_file($_FILES[‘file’][‘tmp_name’],$to);
echo "file is uploaded";

}
?>
</body>
</html>

[/php]

//create a new folder uploaded

TAGS:

Program to insert Background Image

[php]

<html>
<head>
<style type="text/css">
body {background-image:url(‘systeuser/desktop/bc.jpg’);}/*inserting background image*/
</style>
</head>
<body>
<h1>Hello!</h1>
</body>
</html>

[/php]

output:

Hello!

(If u run this code in Internet Explorer,the background image will be displayed with “Hello!” Message).

Calculate add,sub,mul using php

Steps:

1. Create new html file and copy calculate.html code and save it as calculate.html.

2. Create new php file and copy calculation.php code and save it as calculation.php.

3. Run calculate.html, then it will display the html data.

4. Enter value1, value2 and press add or sub or mul button and press calculate button.

5. Then it will transfer to calculation.php which displays the output.

calculate.htm:

[php]

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>calculation</title>
</head>

<body>
<form method=”post” action=”calculation.php”>
Value 1: <input type=”text” name=”val1″ size=”7″><br /><br />
Value 2: <input type=”text” name=”val2″ size=”7″>
<p>
<input type=”radio” name=”calculate” value=”add”  />
add
<input type=”radio” name=”calculate” value=”sub”  />
sub
<input type=”radio” name=”calculate”  value=”mul”/>
mul
</p>
<input type=”submit” name=”submit” value=”calculate”/>
</form>
</body>
</html>

[/php]

It displays the output as:
Value 1: Value 2:
add
sub
mul

calculation.php:
[php]
</form><form action=”calculation.php” method=”post”><!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head><body>
<?php
if(($_POST[‘val1’]==””) || ($_POST[‘val2’]==””))
{
header(“location: calculate.html”);
exit();
}
if($_POST[‘calculate’]==”add”)
{
$result=$_POST[‘val1’]+$_POST[‘val2’];
}
else if($_POST[‘calculate’]==”sub”)
{
$result=$_POST[‘val1’]-$_POST[‘val2’];
}
else if($_POST[‘calculate’]==”mul”)
{
$result=$_POST[‘val1’]*$_POST[‘val2’];
}
echo “Calculation is: $result”;
?>
</body>
</html></form><form action=”calculation.php” method=”post”>
[/php]
An example output for add by giving the input as value1 as 5 and value2 as 5 is:
Calculation is: 10

TAGS:

Transfer data from one page to another using php

Steps:

1:Create new php file and copy file1 code and save it as file1.php.

2.Create another new php file and copy file2 code and save it as file2.php.

3.Run file1.php, then it will display the file1 data.

4.Enter your name, age and location and press the submit button.

5.It will transfer to file2.php and displays the output.

file1:

[php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>table1</title>
<script language="javascript" type="text/javascript">
function check()
{
if(document.getElementById(‘name1’).value==”)
{
alert("Please enter your name");
document.getElementById(‘name1’).focus();
}
else if(document.getElementById(‘age1’).value==”)
{
alert("please enter your age");
document.getElementById(‘age1’).focus();
}
else if(document.getElementById(‘location1’).value==”)
{
alert("please enter the location");
document.getElementById(‘location1’).focus();
}
else
{
document.form.submit();
}
}
</script>
</head>

<body>
<form method="post" action="file2.php" name="form" >
<table width="100%" border="0">
<tr>
<td><label>Enter your name: </label>
</td>
<td><input type="text" name="name"  id="name1"; />
</td>
</tr>
<tr>
<td><label>Enter your age:</label>
</td>
<td><input type="text" name="age" id="age1"; />
</td>
</tr>
<tr>
<td><label>Enter the location:</label>
</td>
<td><input type="text" name="location" id="location1"; />
</td>
</tr>
<tr>
<td colspan="2"> <div align="center">
<input type="button" value="Submit" onclick="check();" name="Submit" />

</div></td>
</tr>
</table>
</form>
</body>
</html>

[/php]

//save this as file1.php

It will display the output as:

file2:

[php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>table2</title>
</head>

<body>
<?php
$var1=$_POST[‘name’];
$var2=$_POST[‘age’];
$var3=$_POST[‘location’];
echo "your name is: $var1"."<br/>";
echo "your age is: $var2"."<br/>";
echo "loaction is: $var3";
?>
</body>
</html>

[/php]

//save this as file2.php

after entering your name, age and location and pressing the submit button, it displays the output.

For example:

your name is: John
your age is: 25
loaction is: CA

TAGS: , ,

Change Your Page Background Color Dynamically using Java Script

Following code is used to change a page color from your select option in select box.

Copy and Paste following code in a simple HTML page.

[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Change Your page Background Color Using Java Script</title>
<script type="text/javascript">
function changeTheme(selColor) {
alert(selColor);
document.body.style.backgroundColor = selColor;
}
</script>

</head>
<body>
<h1>Please Select Your Page Background Color..</h1>
<select name="changescheme" id="changescheme" onChange="javascript:changeTheme(this.value)">
<option value="white">White</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="orange">Orange</option>
<option value="black">Black</option>
</select>
</body>
</html>
[/html]

TAGS: , ,

Giving Links In CSS

/* The Example1 will be having the font styles,colors and  font size for the content present in Example2. copy and paste the code of Example2 to get the output.*/

Example1.css

[css]
body
{
background-color:yellow;
}
h1
{
font-size:36pt;
}
h2
{
color:blue;
}
p
{
margin-left:50px;
}
[/css]

Example2.css

[css]
<html>
<head>
<link rel="stylesheet" type="text/css"  href="example1.css"  />
</head>
<body>
<h1>Hai!!</h1>
<h2>Have A Nice Day</h2>
</body>
</html>
[/css]

Output:

Hai!!

Have A Nice Day

TAGS:

Request a Free SEO Quote