0% found this document useful (0 votes)
4 views7 pages

PHPH

The document discusses client-side and server-side scripting, highlighting their differences, advantages, and technologies used. It explains static and dynamic websites, detailing their characteristics, development costs, and interactivity. Additionally, it covers PHP functions, recursion, string manipulation, file permissions in Linux, and file handling in Python.

Uploaded by

SHUBHAM k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

PHPH

The document discusses client-side and server-side scripting, highlighting their differences, advantages, and technologies used. It explains static and dynamic websites, detailing their characteristics, development costs, and interactivity. Additionally, it covers PHP functions, recursion, string manipulation, file permissions in Linux, and file handling in Python.

Uploaded by

SHUBHAM k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

UNIT-1

Client-side scripting:1.Source code is visible to the user.2.its main function is


to provide the requested output to the end user.3.It usually depends on the
browser and its version.3.It runs on the user’s computer.4.There are many
advantages linked with this like faster response times, a more interactive
application. 5.It does not provide security for data.6.It is a technique used in
web development in which scripts run on the client’s browser7.HTML, CSS, and
javascript are used.8.It reduces load on processing unit of the server.9.No need
of interaction with the server.10.It reduces load on processing unit of the
server.
Server-side scripting:Source code is not visible to the user because its output
of server-sideside is an HTML page. 2.Its primary function is to manipulate and
provide access to the respective database as per the request.3.In this any
server-side technology can be used and it does not depend on the client. 4.It
runs on the webserver.5.The primary advantage is its ability to highly
customize, response requirements, access rights based on user. 6.It provides
more security for data.7.It is a technique that uses scripts on the webserver to
produce a response that is customized for each client’s request.8. PHP,
Python, Java, Ruby are used.9.It is all about interacting with the servers.It
surge the processing load on the server.
A static website is one where the content is fixed and does not change unless
manually updated by a developer. These websites are built using simple technologies
like HTML, CSS, and sometimes JavaScript. Since the pages are pre-rendered, they
load quickly and are easy to develop and deploy. However, they lack interactivity and
are best suited for websites where content remains consistent over time, such as
portfolios or company brochures. Static websites have lower development and
hosting costs but require manual updates for any content changes.
On the other hand, a dynamic website generates content on the fly using server-side
scripting languages like PHP, Python, or JavaScript (Node.js). These websites often
rely on databases to store and retrieve data, allowing content to be updated
dynamically without requiring developer input. Dynamic websites are highly
interactive and can support complex features such as user accounts, shopping carts,
and forms. While they are more expensive to develop and host due to their
complexity, they are ideal for websites that require frequent updates or personalized
user experiences, such as blogs, e-commerce platforms, or web applications. They
may have slower load times compared to static websites, but optimizations like
caching can help improve performance
Q.Loops in PHP are used to execute the same block of code a specified number of
times. PHP supports following four loop types.for − Loops through a block of code a
specified number of times.foreach − Loops through a block of code for each element
in an array.while − Loops through a block of code if and as long as a specified
condition is true.do-while − Loops through a block of code once, and then repeats
the loop as long as a special condition is true.
for loop:loops through a block of code a specified number of times. This for loop is
used when you already know how many times you want to execute a block of
code.This type of loops are also known as entry-controlled loops. There are three
main parameters to the code, namely the initialization, the test condition and the
counter.
for (initialization expression; test condition; increment/decrement expression) {

// code to be executed

while loop loops through a block of code as long as the specified condition is
true.The while loop executes a block of code repeatedly until the condition is false.
Once the condition gets false, it exists from the body of loop.
While (if the condition is true) {

// code is executed

do-while loop loops through a block of code once, and then repeats the loop as long
as the specified condition is true. A statement is executed at least once on using the
do…while loop. After executing once, the program is executed as long as the
condition holds true.
Static WebsitevsDynamic Website
Content of Web pages can not be change at runtime. Content of Web pages can be
changed.No interaction with database possible. Interaction with database is
possibleIt is faster to load as compared to dynamic website.It is slower than static
website.Cheaper Development costs. More Development costs.
No feature of Content Management. Feature of Content Management System.
HTML, CSS, Javascript is used for developing the website. Server side languages such
as PHP, Node.js are used.
Same content is delivered everytime the page is loaded. Content may change
everytime the page is loaded
UNIT2. A function is a block of code written in a program to perform some specific
task. We can relate functions in programs to employees in a office in real life for a
better understanding of how functions work. Suppose the boss wants his employee
to calculate the annual budget. So how will this process complete? The employee will
take information about the statistics from the boss, performs calculations and
calculate the budget and shows the result to his boss. Functions works in a similar
manner. They take informations as parameter, executes a block of statements or
perform operations on this parameters and returns the result.
PHP provides us with two major types of functions:Built-in functions : PHP provides
us with huge collection of built-in library functions. These functions are already
coded and stored in form of functions. To use those we just need to call them as per
our requirement like, var_dump, fopen(), print_r(), gettype() and so on.User Defined
Functions : Apart from the built-in functions, PHP allows us to create our own
customised functions called the user-defined functions.
Using this we can create our own packages of code and use it wherever necessary by
simply calling it.
Creating a Function
Any name ending with an open and closed parenthesis is a function.A function name
always begins with the keyword function.To call a function we just need to write its
name followed by the parenthesis.A function name cannot start with a number. It
can start with an alphabet or underscore.A function name is not case-sensitive.
function function_name(){
executable code;
}
Q.Reusability: If we have a common code that we would like to use at various parts
of a program, we can simply contain it within a function and call it whenever
required. This reduces the time and effort of repetition of a single code. This can be
done both within a program and also by importing the PHP file, containing the
function, in some other program
Easier error detection: Since, our code is divided into functions, we can easily detect
in which function, the error could lie and fix them fast and easily.
Easily maintained: As we have used functions in our program, so if anything or any
line of code needs to be changed, we can easily change it inside the function and the
change will be reflected everywhere, where the function is called. Hence, easy to
maintain.
Q.A recursive function is a function that solves a problem by solving smaller
instances of the same problem. This technique is often used in programming to solve
problems that can be broken down into simpler, similar subproblems.
Components of a recursive function:
Base case: Every recursive function must have a base case. The base case is the
simplest scenario that does not require further recursion. This is a termination
condition that prevents the function from calling itself indefinitely. Without a proper
base case, a recursive function can lead to infinite recursion.
Recursive case: In the recursive case, the function calls itself with the modified
arguments. This is the essence of recursion – solving a larger problem by breaking it
down into smaller instances of the same problem. The recursive case should move
closer to the base case with each iteration.
formal arguments:Formal arguments are the variables defined in the function's
declaration or definition.tThey act as placeholders that receive values when the
function is called.Actual arguments;Actual arguments are the values or variables
passed to the function when it is invoked.
These values are assigned to the formal arguments.
String can also be defined as a sequence of characters, stored in contiguous memory
locations, terminated by a special character called the null character ‘\0’.
Strings are widely used in computer science and have many applications in various
fields, some of which are:

Text Processing: Strings are used to represent and manipulate text data, such as in
text editors, word processors, and other applications that deal with text.
Pattern Matching: Strings can be searched for patterns, such as regular expressions
or specific sub-strings, to extract or process data in a specific way.
Data Compression: Strings can be compressed to reduce the amount of storage
required to store them. String compression algorithms, such as Huffman coding and
run-length encoding, are commonly used in data compression applications.

Q.Library function in PHP are built-in functions provided by the language to perform
various tasks, such as string manipulation, array operations, file handling, mathematical
calculations, and more. Here are some commonly used library functions in PHP:

String FunctionsThese functions are used to manipulate and handle strings.

strlen(): Returns the length of a string echo strlen output("Hello, PHP!"); // Output: 10
Array FunctionsThese functions allow manipulation of arrays.count(): Returns the
number of elements in an arraphp
Copy code)
$arr = [1, 2, 3];
echo count($arr); // Output: 3
File Handling Functions
These functions help in reading, writing, and managing files.fopen(): Opens a file for
reading, writing, or appending.
php
$file = fopen("example.txt", "r");

Date and Time Functions


These functions allow you to work with dates and times.
date(): Formats a local date and time.
echo date("Y-m-d"); // Output: Current date in YYYY-MM-DD format
User-defined library functions are functions that are created by the
programmer and added to a library for later use. These functions can be written
in C or any other programming language that can be compiled into a library.
User-defined library functions can be used to simplify complex
programming tasks, reuse code, and improve code maintainability.

. UNIT-4
permissions is at the core of Unix/Linux file system. The permissions
determine who can access a file and how one can access a file. File
permissions in Linux are manipulated by the chmod command, which can
be run inside the Linux terminal. PHP provides the chmod() function with
which you can handle file permissions programmatically.

PHP’s chmod() function is effective only when you are working on a Linux OS.
It doesn’t work on Windows, as Windows OS has a different mechanism of
controlling file permissions.Types of File Permissions

In Linux/Unix environments, file permissions are typically represented as a combination of


read, write, and execute permissions for three types of users:

1. Owner: The user who owns the file.


2. Group: Users in the file's group.Others: All other users.
Permissions are represented numerically (e.g., 777, 644) or symbolically (e.g., -rw-r--r--).

 Read (r): Allows viewing the file contents.


 Write (w): Allows modifying the file.
 Execute (x): Allows executing the file as a script or program.
 Q File opening and closing in Python, particularly using the open() function, it is crucial to
understand the basics of file handling and how to manage resources efficiently. Python
provides various ways to handle files, including manual opening and closing or using context
managers to automate resource management ile opening and closing in Python, particularly
using the open() function, it is crucial to understand the basics of file handling and how to
manage resources efficiently. Python provides various ways to handle files, including manual
opening and closing or using context managers to automate resource management ile
opening and closing in Python, particularly using the open() function, it is crucial to
understand the basics of file handling and how to manage resources efficiently. Python
provides various ways to handle files, including manual opening and closing or using context
managers to automate resource management

Opening and Closing Files


1. File Open

The open() function is used to open a file in Python. Its syntax is: file_object =
open(file_name, mode)

When discussing file opening and closing in Python, particularly using the open() function,
it is crucial to understand the basics of file handling and how to manage resources efficiently.
Python provides various ways to handle files, including manual opening and closing or using
context managers to automate resource management.

Opening and Closing Files


1. File Open

The open() function is used to open a file in Python. Its syntax is:

python
Copy code
file_object = open(file_name, mode)

 file_name: The name of the file (e.g., "example.txt").


 mode: Specifies how the file is opened. Common modes:
o 'r' - Read (default mode).
o 'w' - Write (creates a new file or overwrites an existing one).
o 'a' - Append (adds content to the end of the file).
o 'b' - Binary mode (used for non-text files, e.g., images).
o 'x' - Exclusive creation (fails if the file exists).
o '+' - Read and write.

Example:
python
Copy code
file = open("example.txt", "r")
content = file.read() # Read file content

2. File Close
After performing operations on a file, it is essential to close it to free system resources. Use
the close() meth
Failing to close a file can lead to resource leaks and potential issues when accessing the file
again.

You might also like