All Php Code requires the beginning and ending Tags to be placed before and after any Php Code as shown below:
<?php //our beginning Tag....
....Code Goes Here....
?> //our ending Tag......
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.
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:
- $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 ';
To convert a Variable into txt to show on the Html Page you have two options both related as follows"
- print $myvar;
- echo $myvar;
Variables For Html Or Html Tags
$html='<html>'; $body='<body>'; $link1='"<" a href="www.freescripts.com ">"'; $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;?>"/>
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//