Web Technology II · Unit 1
PHP Fundamentals and Syntax
Exam-focused notes for PHP Fundamentals and Syntax (Web Technology II, BIT301): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
What this unit covers
- Server side scripting concepts
- Embedding PHP code in web pages
- PHP comments and documentation
- Variable definition and declaration
- Loosely typed language characteristics
- Data types and type casting operators
- String operations and concatenation
Loosely typed language characteristics
Why is PHP a loosely typed language? How is the for loop different from the foreach loop? Write a PHP program to demonstrate the use of both loops.[10]
--- PHP is called a loosely typed (or dynamically typed) language because: - Variables do not require explicit data type declaration - The data type of a variable is automatically determined at runtime based on the value assigned to it - The same variable c...
Full solved answer →Server side scripting concepts
What is server side scripting? How can you define and declare variables in PHP? Write PHP programs to demonstrate concepts of while and do while loops.[10]
--- Server side scripting is a technique used in web development where scripts are executed on the web server rather than on the client's browser. The server processes the script, generates output (usually HTML), and sends only the final result to the clien...
Full solved answer →Embedding PHP code in web pages
How can you embed PHP code in web pages? Write a PHP program to illustrate the concepts of continue and break statements.[10]
PHP (Hypertext Preprocessor) is a server-side scripting language. PHP code is embedded directly within HTML documents using special delimiters (tags). The web server processes the PHP code and sends only the resulting HTML output to the browser. This is the...
Full solved answer →PHP comments and documentation
How are comments written in PHP? Write a PHP program that will read your name and roll number and print the values. Label your program with appropriate comments. [5]
PHP accepts three forms of comment, inherited from the languages it grew out of. Two are single line and one spans several lines, and none of them are sent to the browser: the parser strips them before any output is produced. Form Syntax Extent --------- C+...
Full solved answer →String operations and concatenation
Write a PHP program that will contain a concat string function. The function should have two arguments st1 and st2 of type string and should return st3 which is concatenation of st1 and st2. [5]
Part Description ------------------- function concatString($st1, $st2) Defines a function with two string arguments st1 and st2 $st3 = $st1 . $st2 Uses the . (dot) operator to concatenate the two strings and stores in $st3 return $st3 Returns the concatenat...
Full solved answer →Write a PHP program that will read two input strings in variable fname and lname and display concatenation of fname and lname. [5]
PHP joins strings with the dot operator, so $fname . " " . $lname gives the full name with a single space between the two parts. The two values are typed into an HTML form and read on the server from the $POST superglobal once the form has been submitted. W...
Full solved answer →Variable definition and declaration
How can you define variable in PHP. Illustrate with example. [5]
A variable in PHP is a named storage location that holds a value. PHP variables are loosely typed, meaning you do not need to declare the data type explicitly -- the type is determined automatically based on the assigned value. --- 1. A variable must start ...
Full solved answer →Make Unit 1 stick
Practice BIT301 with flashcards & quizzes