>> PHP: HTML Integration
PHP-HTML Integration PHP within HTML HTML within PHP My name is Mohammed Misbhauddin $name = ‘Mohammed Misbhauddin’; <p>My name is <strong> <?php echo $name; ?> </strong></p> <?php echo ‘<p>My name is <strong>’.$name.’</strong></p> ?> Use concatenation
Case Study Project Setup Download the file work-file to be used Buy4mMe.zip Create New Project in NetBeans/Aptana Set destination path of workspace to the htdocs folder in the XAMPP directory Unzip the downloaded file in D:\xampp\htdocs\project-name folder Web-Based Systems - Misbhauddin
Re-use in PHP Each page has a header and a footer which gets repeated Insert the content of one PHP file into another PHP file before the server executes it Function include or require (Note: Both are same except when they give errors) Usage <?php include(‘file.php’) ?>
Reusing the Header & Footer Create a new PHP file called header.php Copy all the code from top to the div tag with id=“content” and paste it into the new file Delete this code from the index.php file and add the include statement TRY NOW <?php include(‘header.php’) ?> HINT: Repeat the above steps for the footer. Create another file, copy all common footer content to it and replace it in the main file with an “include” php function
Create a New “Contact” Page Create a new PHP file called contact.php Content Div Tag with class section & page Heading 1 with text “Contact Me” TRY NOW Use the header and footer HINT:
Using Variables TRY NOW HOW? ISSUE: Can I change the title of a page if the header and footer are common HOW? Create a new variable in each page called title Set this to the title of that page Use this variable in the header page TRY NOW
Using Conditionals: Navigation States ISSUE: How to change the menu bar current state in a common header? Open the contact.php Add another variable called section with a value of “contact” Now go to the header.php page Add the class “on” to the links Modify it using conditionals so that it is “on” when we are on a specific page TRY NOW Add the php code inside the class attribute of the <li> tag HINT:
Web-Based Systems - Misbhauddin Next on PHP Arrays Regular Arrays Associative Arrays Web-Based Systems - Misbhauddin