Docsity

PHP Programming Fundamentals: Data Types, Functions, and Form Handling, Exercises of Database Programming

Partial preview of the text

Download PHP Programming Fundamentals: Data Types, Functions, and Form Handling and more Exercises Database Programming in PDF only on Docsity!

Data Types

 Scalar Data Types & Compound Data Types Scalar Data Types: Integer , float or double ( 1.23/ 10.2e3), boolean, string,unicode(sequence of unicode characters), binary Compound Data Types Array, Objects Special Data Types Null, resource

Functions

Better code organization – functions allow us to

group blocks of related code that perform a specific

task together.

Reusability – once defined, a function can be called

by a number of scripts in our PHP files. This saves us

time. Ex: database connection..

Easy maintenance- updates to the system only need

to be made in one place.

String Functions

strlen() - to calculate the number of characters inside

a string.

It also includes the blank spaces inside the string.

str_word_count() - Counting Number of Words in a

String

str_replace() - replaces all occurrences of the search

text within the target string.

Ex: <?php

$my_str = “Guru Nanak College I MCA “;

echo str_replace(“I", “I Year ", $my_str);

str_replace(“I ", “I MCA", $my_str, $count); Count- to know how many times the string replacements was performed strrev() - function reverses a string. strpos() - to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE. Ex:

Str_repeat(string,repeat) - repeating a string a

specific number of times.

Ex: echo str_repeat(“*”,13);

Strcmp(string1,string2) - It returns output either

greater than zero, less than zero or equal to zero.

substr( string,start,length ) - can display or extract

a string from a particular position.

Converting lowercase into Title Case

Strstr(“string”,”search string”) Find the first occurrence of “search string" inside “string" and return the rest of the string: Ex:

o/p – World! strstr( _string,search,before_search_ )  _before_search -_ Optional. A boolean value whose default is "false". If set to "true", it returns the part of the string before the first occurrence of the _search_ parameter. Ex: O/p:- Hello

MULTIPLE SUBMIT BUTTONS IN A SINGLE FORM

**

**

Max, minPi() - echo(pi())Pow(x,y)Round(number, optional) round(3.4)3 round(3.5)- > 4 Round(1.9562,2)-> 1.

Date Functions

the form data is sent to a web page on the server when the

user clicks on the submit button.

This page(action_page.php) contains a server-side script that

handles the form data:

The Method Attribute –

The method attribute specifies the HTTP method ( GET or

POST ) to be used when submitting the form data:

(or)

When to Use GET?

The default method when submitting form data is GET.

The GET method is restricted to send upto 1024 characters

only.

Never use GET method if you have password

GET can't be used to send binary data, like images or word

documents, to the server.

when GET is used, the submitted form data will be visible in

the page address field(Query String)

Ex: /action_page.php?firstname=Mickey&lastname=Mouse