Posts

Showing posts from September, 2014

Save HTML Content into Database

Generally we have required to save HTML Content i.e. a HTML page or a Block of content into Database. But if we Directly save it to Database, Its throw error due to Special Character and Quotation in the Content.

    So First we have to Convert it to database supported Value. We can do it by Decoding the html.
In PHP we have a Function "htmlspecialchars" and for Decoding the Function is "htmlspecialchars_decode".

So Here is the Code:

Create a Form into a File i.e. "form.php".In this Example, we will get only one input on textarea.Code will be as Follow: ######################## Code for form.php ######################## <html>
<head>
<title>
Form For HTML Element Save into Database.
</title>
</head>

<body>

<div style="width:250px;margin:0px auto;background:#666666;padding: 20px;">

<h4>
Save HTML Content into Database
</h4>

<form action="saveform.php" method="POST">
<texta…

How to Connect Twitter to Facebook

Image
To Connect to Twitter to Facebook.

Just open the Following Twitter link:

https://twitter.com/settings/profile/https://facebook.twitter.com/ 

Follow the step given there, Just a Easy step, you have to just Click Connect to Facebook.


How to Connect Facebook to Twitter

Image
To Connect to Facebook to Twitter,

Just open the Following Facebook link:


https://www.facebook.com/twitter/
Follow the step given there, Just a Easy step, you have to just Click Link to Twitter.

How to Work with Select Box after POST Data in PHP

Everytime We create a form, we used Fields like Text-BOX, Select Box, Radio and Checkbox, Here we will understand a Function to POST data to be selected on database.

PHP Code
 <?php

function isselected($value,$optionvalue)
                        {
                                 if ( $value == $optionvalue )
                                                         {
                                                                  return "selected='selected'";
                                                         } else {
                                                               return false;
                                                          }
                        }


echo "<form method="POST">";


            if(isset($_POST['selectbox']))
                     {
                                 $valueselected = $_POST['selectbox'];
                      }

            echo "<select name="selec…

Plane Example in JQuery

Please Follow the Link for DEMO

A Program in Jquery for Excercise - Jquery

Image
A Program in Jquery for Pity - Jquery:
Style to be Define (CSS):
body { margin:0px; padding:0px;background:#cc0000; }
.container { margin:0px auto; padding:10px; background:#0f0f0f; position:relative; min-height:100%; width:350px; text-align: center; }
.container img { display:none; max-width:100%; }
.container h3 { background: #cc0000; color: aqua; padding: 5px 5px; font-size: 35px; font-weight: normal; font-family: arial; }

Script to be Define (.js file):
/* A JQuery Program to run a Excercise */
function startpity()
{
$("#gamestatus").val('1');
}
function stoppity()
{
$("#gamestatus").val('0');
}

var runningtimer = 0;
var starttimer = 0;
var stoptimer = 0;

function runthepity()
{
runningtimer++;
var gamestatus = $("#gamestatus").val();
if( gamestatus ==1  )
{
starttimer++;
console.log('pity is run for '+starttimer+ "seconds");
var runningslide = $("#runningslide").val();
runningslide = Number(runningslide)+1;
if(runningslide>4)
{
runni…

A Program to Printing a Box from For loop.

A Program to Printing a Box from For loop.

#################################### PHP Code ####################################
<?php

echo "<table cellspacing= '0' cellpadding= '0'><tr>";

for ($i=1;$i<=30;$i++)
{
echo "<td>";
for($j=1;$j<$i;$j++ )
{
echo "*";
echo "<br/>";
}
echo "</td>";
}


for ($i=1;$i<=30;$i++)
{
echo "<td>";
for($j=30;$j>=$i;$j-- )
{
echo "*";
echo "<br/>";
}
echo "</td>";
}

echo "<table><tr>";

?>

#################################### O/P of the Code #################################### **
**
*
**
*
*
**
*
*
*
**
*
*
*
*
**
*
*
*
*
*
**
*
*
*
*
*
*
**
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
**
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*

PHP function call of a another class within another class

################################ PHP CODE ################################
<?php
// function call of a another class

class class1
{

function function1()
{
return 123;
}

function function2()
{
return 259;
}

}


class class2
{

function function1()
{
$object = new class1();
echo $object->function1()+$object->function2();
}

}

$obj = new class2();
$obj->function1();

// function call of a another class

echo "<hr/>";

echo "Above Exapmle Basic : " . (123+259);
echo "<hr/>";

?>

################################ Output of the  CODE ################################ 382
Above Example Basic : 382

PHP Function definition within in a class

######################## PHP CODE ######################## <?php
// function definition within in a class

class common
{

function addition($a,$b)
{
echo "<br/> Sum of the " . $a . " and  " . $b . " is : " . ( $a + $b ) ;
}

function multiplication($a,$b)
{
echo "<br/> Multiplication of the " . $a . " and  " . $b . " is : " . ( $a * $b ) ;
}
}
// function defination within in a class
// object creation for class
$com1 = new common();
// object creation for class
// function call via class's object
$com1->addition(2,3);
$com1->multiplication(2,3);
// function call via class's object
?>

                   ########################                        OUTPUT of the CODE ######################## Sum of the 2 and 3 is : 5
Multiplication of the 2 and 3 is : 6

Function definition with returning some value - PHP

############################
PHP Code
################### ########
<?php         // function definition with returning some value  function sum($a,$b)   {      $sum = $a + $b;   return $sum;  }  function minus($a,$b)  {    $minus = $a - $b;  return $minus;  }  // function definition with returning some value  // use of return function as a variable  echo "Sum of 2 and 3 is : ".sum(2,3);  // use of return function as a variable  // function definition with returning some value  ?> ############################ Output of the Code ############################
Sum of 2 and 3 is : 5

Function definition with returning array value - PHP

####################### PHP Code ####################### <?php
function callmeforarray($a,$b)
{
$addition = $a + $b;
$minus = $a - $b;
$multiplication = $a * $b;
$division = $a / $b;
$modulus = $a % $b;

$returnvalue['sum'] = $addition."<br/>";
$returnvalue['min'] = $minus."<br/>";
$returnvalue['mul'] = $multiplication."<br/>";
$returnvalue['div'] = $division."<br/>";
$returnvalue['mod'] = $modulus."<br/>";

return $returnvalue;
}

echo "<hr/>";

$result = callmeforarray(30,5);
echo "Sum is : ". $result['sum'];
echo "Min is : ". $result['min'];
echo "mul is : ". $result['mul'];
echo "div is : ". $result['div'];
echo "mod is : ". $result['mod'];

$result = callmeforarray(34,2);

echo "Sum is : ". $result['sum'];
echo "Min is : ". $result['min'];
echo "m…

PHP Function call - Just running the code within it

############################ PHP Code ############################ Program 01:      Normal Function just running the code within it
<?php
   //  Normal Function just running the code within it
   //  function definition
 function callme($a,$b)
  {
    // echo "<br/>Sum of the ".$a." and ".$b. "is = ".$a+$b;  
    echo "<br/>Sum of the ".$a." and ".$b. "is = ".($a+$b);  
    echo "<br/>Multi of the ".$a." and ".$b. "is = ".$a*$b;  
    echo "<br/>Min of the ".$a." and ".$b. "is = ".$a-$b;  
    echo "<br/>Divide of the ".$a." and ".$b. "is = ".$a/$b;  
    echo "<br/>Modulus of the ".$a." and ".$b. "is = ".$a%$b;  
  }
   // function defination

    // function call
     callme(2,5);
    // function call

?>


############################ Output of the Code ##############…

Basic for Function on PHP

Function:
       Function are a set of bloch, which are defined for calling a set of code again and again.
There are two way to calling a function in PHP:

Directly calling a Function.Function called by a object of a class and defined within a class.  They are Important as some of the code, we have to use different location on a site. So a good way is to define in a File i.e. "functions.php" and include it to top of the position.


############################ PHP Code ############################ Program 01:      Normal Function just running the code within it <?php
//  Normal Function just running the code within it
//  function definition
function callme($a,$b)
{
// echo "<br/>Sum of the ".$a." and ".$b. "is = ".$a+$b;
echo "<br/>Sum of the ".$a." and ".$b. "is = ".($a+$b);
echo "<br/>Multi of the ".$a." and ".$b. "is = ".$a*$b;
echo "<br/>Min of the ".$a." …

Type of the Variable

Here we will understand, How we can know the type of the variable. As PHP automatic set the type to the variable as we defined it, But sometime it is neccessary to check the type of the variable.
Suppose you have a condition, that it there is more then 10 Items in store,  you will add them all for calculation of the total payment, but when  the item is only one, there is no need to adding them, as the total cost will be cost of the item.
So you can do by checking the variable type of the variable m If it is array then we will add them all, if this is only a string or Integer, and it is the final cost.
Example you have an Variable $value.
if it is array, we will use array function to check as follow:

<?php
                               $totalcost = 0;    if( is_array ($value) )               {                    foreach ( $value as $single )                       {                              $totalcost = $totalcost + $value;
                      }               } else {       …

Loop in PHP - For Loop

So we are going to understand the for loop.

As you know the loop is a re-execute of a block code for the some condition to be true.
For example, I will keep waking till I reached the temple. Here Temple is a condition and walk is the block of code to be executed.
The structure of the for loop as follow: for  ( {initial value for the loop} ; { contion to be check } ; { initial value to be changed } ) {
}
#################################### PHP Code ####################################
<html>
<head>
<title>Loop Example- for</title>
</head>

<body> <h3> Example 1 </h3> <?php  for ( $i = 1 ; $i < 5 ; $i++ )  { echo "<br/> The Value ot the Intiator : " . $i ; } ?> <hr/> <h3> Example 2 </h3> <?php  for ( $j = 5 ; $j > 1 ; $j-- )  { echo "<br/> The Value ot the Intiator : " . $j ; } ?> <hr/>
<h3> Example 3 </h3> <?php  $i = 1; for ( $j = 5  ; $j > 1  ;  $j-- )  { echo "<br/> Th…

Loop in PHP - while loop

There is three main loop in PHP: 

whileforforeach

while:

  while(condition)
{
do this
}


################################### PHP Code ###################################
<html>
<head>
<title>Loop Example</title>
</head>

<body>

<?php


/*
one way of using loop:
in this Program will check condition First and
execute block of code within it, if the condition is true

*/

echo " <br/> ";

$i = 0;
while( $i < 10)
{
echo $i;
echo " <br/> ";
$i++;   // will increment i with 1
}


echo " <hr/> ";


$j = 0;
do
{
echo $j;
echo " <br/> ";
// will increment j with 1
$j++;
}
while ( $j < 10 )

?>

</body>

</html>

Logical Expression in PHP

Today, we will talk about logical expression in PHP.
Syntax of the Logical expression are same as the other Programming languages i.e. C and java.
Syntax:
if Condition:
if(condition)
 run this
if else Condition:
if(condition)  run this
else
run this
nested if else Condition:
if(condition)  run this
else if
 run this
else run this


############################ PHP Code
############################
<?php $a = 4; $b = 5;
// if condition if( $a > $b )// if no curly braces is used, then only next line will be executed  echo " <br/> a is  greater then b "; echo " <br/> this will not depend on the condition "; echo " <hr/> "; if( $a < $b ) echo " <br/> a is  less then b "; echo " <br/> this will not depend on the condition "; echo " <hr/> "; if( $a > $b )// if curly braces is used, then next line will also depend on condition  { echo " <br/> a is  greater then b"; echo " <br/>…