Php Tags
All Php Code requires the beginning and ending Tags to be placed before and after any Php Code as shown below:
Html here-->
<?php    //our beginning Tag....
....Code Goes Here....
?>       //our ending Tag......
Html here-->
Php is very dynamic in that it is able to work in segments within Html or can create any Html. Even better you can use Php to handle a broken down Html Template into smaller page-parts to incorporate data into them dynamically as well.

Php Variables
Variables can be any letter and numbers or characters as long as they begin with the dollar sign "$" then a letter first and cannot use the "?" character it is reserved for Php. Some examples are shown below:
  • $myvar
  • $myvar1
  • $avar12
Variables And Strings
  • $header='Welcome to my cool website !';
  • $paragraph1='Our site is dedicated to web development and offers free learning in the GNU free open source content program ';
Variable Output
To convert a Variable into txt to show on the Html Page you have two options both related as follows"
  • print $myvar;
  • echo $myvar;
Both within the Php Short Tags(<?php --do code--;?>) shown below in the Html section explains the echo and print functions in more detail.
Variables For Html Or Html Tags
$html='<html>'; $body='<body>'; $link1='"<" a href=" ">"'; $image1='"<"img src="path/images/banner.jpeg"/>"'; etc.

Variables can be best used for storing temporary Html tag fillers so you can use one page template for the whole website without re creating more pages. This will allow you to use only one page to present several pages or many pages and the variables then fill the Tilte, Meta, Menu, or even the Cms Style Sheet to be used:
  • $title='Home';    //Ex: <title><?php print $title;?></title>
  • $css='style.css';//Ex: <style type="text/cms"><?php echo $css;?></style>
  • $banner='img/banners/ban.jpeg';//Ex: <img src="<?php echo $banner;?>"/>
Variable Math
Variables can also store numbers for Math or any calculation functions see below:
  • $retail = '100'; //form submitted data or$post[retail]//
  • $cost =  '50';  //form submitted data or $post[cost]//
  • $profit = ($retail - $cost); //subtraction//
  • $divide = ($profit / $retail);  //devision//
  • $math = ($divide * 100);  //get percentile//
  • $percent = floor(($math) * 100 + .5) * .01; // with .001 result=00.000 this removes trailing zero's//

No comments:

Post a Comment