abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

5/22/2018

How to define PHP variable & use in html


Hi,
PHP how to define variable in PHP
Generally use $ symbol to variable some cases const or global is use for global use of variable within file.
What is variable : variable is entity or say object where user can store information or use for such as number, character, string.
Eg:
$ab =100;  this is number or constant form of variable .
$ab = ‘hi’ set of character get string.
$ab =’10.256’ storing float number.
$ab =’<div><p>HI Hello how are you</p></div>’;
Above html code pass into variable so that it can easily call html or reference to number of pages.
  Eg: in one file pass php code & you need this variable to another pages , then call php
By <?php include ‘ab.php’; ?>
& <html>
<body>
<?php echo $sqrt; ?>
</body>
</html>
In above case pass variable in html code & result is in ab.php file $sqrt variable.
Suppose you are connecting to mysql database for getting data. Then call connection & get value in one variable of php file & call it in any number of file i.e. reference passing.
Simple addition program of Variable .
<?php
$a = 10 ;
$b = 50;
$c = $a +$b;
echo $c;
 ?>
In above code output is 60 a & b variable pass to c variable & echo output result.
Note: Semicolon is necessary for each line.
Thanks for viewing blog send comment in case any query.

PHP session, cookie creation & use .



Question : - How create define session variable & what is cookies how to set cookies.
Session are temporary storage variable, by using session you can get variable value in another file .
Session_start();
Session[‘ab’] = ‘hello’;
Session_close();

PHP session is easily started by call it session_start() function. this function first checks if a session is already started and if none is started then it starts one. It is recommended to put the call to session_start() at the beginning of the page.
Session variables are stored in associative array called $_SESSION[]. These variables can be accessed during lifetime of a session.
<?php
   session_start();
   if( isset( $_SESSION['ab'] ) ) {
      $_SESSION['ab'] -= 1;
   }else {
      $_SESSION['ab'] = 1;
   }
       
   $msg = "value of ab is ".  $_SESSION['ab'];
   $msg .= "in this session.";
?>

  <html>
   <head>
      <title>define session</title>
   </head>
    <body>
      <?php  echo ( $msg ); ?>
   </body>
   </html>
Similarly use session_destroy() destroy current session.
& session_close() use to close started session.
Let us see cookies , as similar to session cookies are text file to store user information.
An alert or popup message most of site are uses, eg : we are using your cookies to store information for better performance.
<?php
   setcookie("name", "mayor abc", time()+1600, "/","", 0);
   setcookie("age", "34", time()+1600, "/", "",  0);
?>
   <html>
   <head>
   <title>how to define Cookies with PHP</title>
   </head>
   <body>
      <?php echo "hi setting cookies"?>
   </body>
   </html>
In next session we see more detail.
Thanks for viewing blog send comment in case any query.

Working with HTML & PHP


Working with HTML & PHP
In this section we learn some basic of PHP :
PHP is hypertext Preprocessor .
Is server side scripting language.
While working with website : first execution of client side code then server side code.
<html>
<?php   include ‘abc.htm’; ?>
<body>
<p>hi hello</p>
</body>
</html>
In above example shows Para which execute first then fetch server side code ie abc.htm file code. If there is clear solution or clear code then all this works in 2 -3 second . remember website should load in maximum 3 -4 second or less.
HTML Code Execute first as its client side code
HTML + PHP
PHP Code server side execute
Browser display output


fig: shows how PHP Work with HTML.
Save file with .php  or .htm extension but in case html or htm need add .htaccess file to root folder.
Remember php not working directly in browser it need xampp or wamp like localhost or hosting server.
Basic syntax :
<?php
echo ‘hello world’;
?>
In above hello world is shown as output.
$ab => is variable declaration syntax. No need int or str or var like add simply put $ symbol.
Variable also used to add html code so that refer to other page  or repeated in different location.
We see more detail in next blog.
Thanks for viewing blog send comment in case any query.

CSS background & effect


HTML , css  Background & effect on div
Background of div or table or span or para or any html element will be set using css .
Following different style are used while setting background
1)      Background : setting background of element:  such as image or color or center or different position , repeat or not repeat , set size to 100% 100% รจ background size
Eg:
<html>
<body>
<style>
div
{
Background:  url(‘abc.png’);
Height:150px;
Padding:0;
Margin:0;
}
</style>
<div>
Hi hello how are you
</div>
</body>
</html>
2)  background-image:  specific to only set image in above property of background you can set both image or color
syntax: background-image:url(‘abc.png’);

3)      background-attachment :  setting background attachment whether fixed or flexible
4)      background-color :  setting background color there are different color available in css such hexa , rgb, rgba .
5)      background-position: left, right , top, right different position or center
6)      Background-repeat: whether repeat or not repeat .  repeat to x or y
7)      Background-blend-mode : to set blend mode of background such as color, color-burn, color-darken , color-diffrence, normal , multiply saturation this are different blending mode.

Thanks for viewing blog send comment in case any query.

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...