Monday, March 16, 2015

How to create a calculator using PHP?

<html>
<head>
<title>Simple PHP Calculator</title>
</head>
<body>
<form method="post" action="calculator.php">
<input type="text" name="value1">
<input type="text" name="value2"><select name="action">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="submit" name="submit" value="Calculate Now"></form>
<?php
if(isset($_POST['submit'])){
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$action = $_POST['action'];
if($action=="+"){
echo "<b>Your Answer is:</b><br>";
echo $value1+$value2;
}
if($action=="-"){
echo "<b>Your Answer is:</b><br>";
echo $value1-$value2;
}
if($action=="*"){
echo "<b>Your Answer is:</b><br>";
echo $value1*$value2;
}
if($action=="/"){
echo "<b>Your Answer is:</b><br>";
echo $value1/$value2;
}
}
?>
</body>
</html>

Saturday, March 14, 2015

How to Redirect your 404 page to the Home Page in WordPress.


404’s are part of every website. A while ago we compiled a list of some pretty cool WordPress 404 designs. When coding a one page site, you might not have the time to create a custom 404 page. In which case, you might as well redirect the 404 page to your site’s homepage. In this article, we will show you how to redirect 404 page to home page in WordPress.
All you have to do is open your 404.php file in your theme’s folder. If it doesn’t exist, then create a blank php file. Paste the following code in there:
<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: ".get_bloginfo('url'));

exit();

?>

That’s all. Now when a user hits a 404 page will be redirected to the homepage.
Note: This should be used in very specific cases. In most other cases (i.e blogs, portfolios etc), you should track your 404 pages and redirect them appropriately.

Friday, March 13, 2015

str_repeat function.

Definition

string str_repeat ( string $input , int $multiplier )

Description

Returns input repeated multiplier times.

Parameters




Result

$result (plain text):

Code

<?php
$input 
'*';

$multiplier 5;
$result str_repeat ($input$multiplier);
?>

HOW TO CREATE THE MYSQL BACKUP?

Easy way to create the mysql backup file

<?php 
/* Create the mysql backup file */
define(‘DB_NAME’‘databaseName’);
/** MySQL database username */
define(‘DB_USER’‘dataUser’);
/** MySQL database password */
define(‘DB_PASSWORD’‘dbPassword’);
/** MySQL hostname */
define(‘DB_HOST’‘localhost’);
$dbhost = DB_HOST;
$dbuser = DB_USER;
$dbpass = DB_PASSWORD;
$dbname = DB_NAME;
$sqlfile = $dbname date("Y-m-d") . ‘.sql.gz’;
system("mysqldump -h $dbhost -u $dbuser –password=$dbpass $dbname | gzip > $sqlfile");
?>

HOW TO MAKE THE STAR TRIANGLE IN PHP?

It is very easy to make a STAR Triangle in php .This is a type of matrix in which we can print rows and columns .You can make the STAR triangle by using (for loop) or (foreach) loop in php. For or foreach loop make it very easy in to make STAR Triangle.This can improve the logic of Fresher . Check below the programming syntax in front of output:
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
1
2
3
4
5
6
7
8
<?php
for($i=0;$i<=5;$i++){
for($j=5-$i;$j>=1;$j--){
echo "*&nbsp;";
}
echo "<br>";
}
?>
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
1
2
3
4
5
6
7
8
9
</pre>
<?php
for($i=0;$i<=5;$i++){
for($j=1;$j<=$i;$j++){
echo "*&nbsp;";
}
echo "<br>";
}
?>
 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
1
2
3
4
5
6
7
8
<?php for($i=0;$i=$i;$k--){
echo " ";
}
for($j=1;$j<=$i;$j++){
echo "*"." ";
}
echo "<br>";
}?>
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
1
2
3
4
5
6
7
8
9
10
11
12
<?php
 
for($i=5;$i-->=0;$i--){
for($k=5;$k>=$i;$k--){
echo "  ";
}
for($j=1;$j<=$i;$j++){
echo "*  ";
}
echo "<br>";
}
?>
 *
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
for($i=0;$i<=6;$i++){
for($k=6;$k>=$i;$k--){
echo " &nbsp;";
}
for($j=1;$j<=$i;$j++){
echo "* &nbsp;";
}
echo "<br>";
}
for($i=5;$i>=1;$i--){
for($k=6;$k>=$i;$k--){
echo " &nbsp;";
}
for($j=1;$j<=$i;$j++){
echo "* &nbsp;";
}
echo "<br>";
}
?>




1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1
2
3
4
5
6
7
<?php
for($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo $j;
}
echo “<br>”;
} ?>
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
1
2
3
4
5
6
<?phpfor($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo $i;
}
echo "<br>";
} ?>
1
1 1
1 1 1
1 1 1 1
1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1 1
1
2
3
4
5
6
<?phpfor($i=0;$i<=7;$i++){
for($j=1;$j<=$i;$j++){
echo "1";
}
echo "<br>";
} ?>