Documente Academic
Documente Profesional
Documente Cultură
Objective: The purpose of this lab is to explore PHP and to learn how to use the PHP
programming language to solve problems and to use it to fulfill classic web functions such as
forms treatment.
Exercise 3: Strings
1. Using the strlen() function, write a loop that displays each letter of a string (of your
choice) on a separate line.
2. Write a PHP script that checks if a string contains the word zut. If the string
contains the word zut then the following should be displayed The string contains a
bad word. And if it does not contain it the string in question should be written in
bold.
You can use the PHP function eregi() is this exercise.
Exercise 4: Arrays
1. Write a PHP script that creates an array containing email addresses. You can use the
following email addresses as an example:
php@free.com
php2@free.com
slimshady@yahoo.com
yoyoyo@gmail.com
yoyo@hotmail.com
xoxo@live.com
cs220@gmail.com
cs220@yahoo.com
cs220@free.com
gg@gmail.com
tbs@tbs.com.tn
2. Extract the domain names from the email addresses and put them in a separate array.
Each domain must have only one occurrence in this new array.
You may use the foreach() construct to work on the original array and the
explode() function to extract the domain name from the email adres.
3. Write down the statistics of the usage of each domain name in the original array
following this example:
The domain name free.com = 23.5 %
The domain name gmail.com = 16.1%
2. Add a Javascript to the PHP script that displays the entered data only if all the fields
contain values. If there is at least one of the fields that is empty, the Javascript should
display an alert box saying One or more fields are empty. Please check your
coordinates..