2CEIT6PE1 WT Practical-4-1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Practical-4 Web Technology

GANPAT UNIVERSITY
U.V. PATEL COLLEGE OF ENGINEERING B.Tech
6th Semester CE/IT

2CEIT6PE1: Web Technology

Practical-4

Aim: Perform following programs of PHP String & it’s inbuilt function.

Exercise:

1. Write following PHP programs of String variable:

1) To concatenate two string variables.

Code :

<?php

// First String
$string1 = JINAL ';

// Second String
$string2 = 'ARDESHANA';

// Concatenation Of String
$concatenatestring= $string1.$string2;

// print Concatenate String


echo " $concatenatestring \n";
?>

OUTPUT:

1
21012012002 (Ardeshana Jinal)
IT-D(AB15)
Practical-4 Web Technology

2) To find the length of a string.

Code :
<?php
$str1 = ‘ARDESHANA JINAL ‘;
echo strlen($str1);
echo "<br>";

$str2 = 'SURAT';
echo strlen($str2);
?>
OUTPUT:

2. Write a PHP program that will compare two stings whether they are
same or not.

Code :

<?php

// Declaration of strings
$name1 = "JINAL";
$name2 = "JINAL";

// Use == operator
if ($name1 == $name2) {
echo 'Both strings are equal';
}
else {
echo 'Both strings are not equal';
}
?>

OUTPUT:

2
21012012002 (Ardeshana Jinal)
IT-D(AB15)
Practical-4 Web Technology

3. Write a PHP program that will convert a string into lowercase string
and uppercase string.

Code :
<?php
$str =
"JINALARDESHNA "
;echo strtoupper($str);
echo strtolower($str);
?>

OUTPUT:

4. Write a PHP program to find a position of a given character into given


string.

Code :
<?php

// Consider the string


$str1 = "ARDESHANAJINAL";

// Get the position of 'f' character


echo strpos($str1, 'H’);
echo "\n";
?>
OUTPUT:

3
21012012002 (Ardeshana Jinal)
IT-D(AB15)
Practical-4 Web Technology

5. Write a PHP program to replace one string using another string.

Code :

<?php
//input string
$string="JINAL ARDESHANA";
//replace geeks in the string with computer
echo str_replace("JINAL","RAVI",$string);
?>

OUTPUT:

6. Write a PHP function vowelCount() which accepts a string as a


parameter, and returns the number of vowels in the in string. Vowels
include a, e, i, o, and u. You may assume the string will be all
lowercase.

Code :
<?php

function isVowel($ch)
{
;
return ($ch =='A' || $ch =='E' ||
$ch =='I' || $ch =='O' ||
$ch =='U'||$ch == 'a'||
$ch == 'e'||$ch == 'i'||
4
21012012002 (Ardeshana Jinal)
IT-D(AB15)
Practical-4 Web Technology

$ch == 'o'||$ch == 'u');


}

function countVowels($str)
{
$count = 0;
for ($i = 0; $i < strlen($str); $i++)if (isVowel($str[$i]))
++$count;
return $c

OUTPUT:

7. Write a PHP program to print an arithmetic progression series.


[Input : $a = 200, $b = 250, $d = 10
Output : 200, 210, 220, 230, 240, 250

Input : $a = 10, $b = 100, $d = 20


Output : 10, 30, 50, 70, 90]
Code :
<?php
function printAP($a, $b, $d)
{
$array=[];
$x=0;
for ($i = $a; $i < $b; $i+=$d)
{
$array[$x]=$i;
$x++;
}
echo(implode(",",$array));
}
5
21012012002 (Ardeshana Jinal)
IT-D(AB15)
Practical-4 Web Technology

$a = 1;
$b = 100;
$d = 5;
printAP($a, $b, $d);
?>

OUTPUT:

6
21012012002 (Ardeshana Jinal)
IT-D(AB15)

You might also like