This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter-12: Exercises | |
// Question-1 | |
// 1. This program has a syntax error in it: | |
$name = 'Umberto'; | |
function say_hello() { | |
print 'Hello, '; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter-10: Exercises | |
// Question-1 | |
// 1. Make a web page that uses a cookie to keep track of how many times a user has viewed the page. | |
// The first time a particular user looks at the page, it should print something like “Number of views: 1.” | |
// The second time the user looks at the page, it should print “Number of views: 2,” and so on. | |
// Answer-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter-8: Exercises | |
// The following exercises use a database table called dishes with the following structure: | |
// -- CREATE TABLE dishes ( | |
// -- dish_id INT, | |
// -- dish_name VARCHAR(255), | |
// -- price DECIMAL(4,2), | |
// -- is_spicy INT | |
// -- ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter-7: Exercises | |
// Question-1 | |
// 1. What does $_POST look like when the following form is submitted with the third option in the Braised Noodles menu selected, | |
// the first and last options in the Sweet menu selected, and 4 entered into the text box? ?> | |
<form method="POST" action="order.php"> | |
Braised Noodles with: <select name="noodle"> | |
<option>crab meat</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The PricedEntree class referencing that namespace: | |
class PricedEntree extends Entree { | |
public function __construct($name, $ingredients) { | |
parent::__construct($name, $ingredients); | |
foreach ($this->ingredients as $ingredient) { | |
if (! $ingredient instanceof \Meals\Ingredient) { | |
throw new Exception('Elements of $ingredients must be Ingredient objects'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter-5 | |
// Question-1 | |
// 1. Write a function to return an HTML <img /> tag. | |
// The function should accept a mandatory argument of the image URL and optional arguments for alt text, height, and width. | |
// Answer-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter-4: Exercises | |
// Question-1 | |
// 1. According to the US Census Bureau, the 10 largest American cities (by population) in 2010 were as follows: | |
// • New York, NY (8,175,133 people) | |
// • Los Angeles, CA (3,792,621) | |
// • Chicago, IL (2,695,598) | |
// • Houston, TX (2,100,263) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter - 2: Exercises | |
// Question-1 | |
// 1. Find the errors in this PHP program: | |
// 1. The opening PHP tag should be just <?php with no space between the <? and php. | |
// 2. Because the string I'm fine contains a ', | |
// it should be surrounded by double quotes ("I'm fine") or the ' should be escaped ('I\'m fine'). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Chapter - 3: Exercises | |
// Question-1 | |
// 1. Without using a PHP program to evaluate them, determine whether each of | |
// these expressions is true or false: | |
// a. 100.00 - 100 | |
// b. "zero" | |
// c. "false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Step-1: | |
// create a script server file at the project root e.g. server.js | |
const path = require('path'); | |
const express = require('express'); | |
const app = express(); | |
const port = process.env.PORT || 3000; | |
const publicPath = path.join(__dirname, 'build'); | |
// serve the build folder |