Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

php programs for second year information technology students, Summaries of Internet and Information Access

practical program list for php which uses xamp coding

Typology: Summaries

2022/2023

Uploaded on 03/21/2024

devika-jayaseelan
devika-jayaseelan 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
STRING HANDLING
<?php
// Function to count the number of words in a string
function countWords($str) {
$words = str_word_count($str);
return $words;
}
// Function to reverse a string
function reverseString($str) {
$reversedStr = strrev($str);
return $reversedStr;
}
// Function to convert a string to uppercase
function convertToUppercase($str) {
$uppercaseStr = strtoupper($str);
return $uppercaseStr;
}
// Function to convert a string to lowercase
function convertToLowercase($str) {
$lowercaseStr = strtolower($str);
return $lowercaseStr;
}
// Sample string
$string = "Hello World! This is a PHP program for PG students.";
// Count words in the string
$wordCount = countWords($string);
echo "Number of words in the string: $wordCount<br>";
// Reverse the string
$reversedString = reverseString($string);
echo "Reversed string: $reversedString<br>";
// Convert the string to uppercase
$uppercaseString = convertToUppercase($string);
echo "Uppercase string: $uppercaseString<br>";
// Convert the string to lowercase
$lowercaseString = convertToLowercase($string);
echo "Lowercase string: $lowercaseString<br>";
?>
pf3
pf4

Partial preview of the text

Download php programs for second year information technology students and more Summaries Internet and Information Access in PDF only on Docsity!

STRING HANDLING

"; // Reverse the string $reversedString = reverseString($string); echo "Reversed string: $reversedString
"; // Convert the string to uppercase $uppercaseString = convertToUppercase($string); echo "Uppercase string: $uppercaseString
"; // Convert the string to lowercase $lowercaseString = convertToLowercase($string); echo "Lowercase string: $lowercaseString
"; ?>

OPERATORS

// Multidimensional Array $employees = array( array("name" => "Alice", "department" => "HR", "salary" => 50000), array("name" => "Bob", "department" => "IT", "salary" => 60000), array("name" => "Charlie", "department" => "Finance", "salary" => 55000) ); echo "\nMultidimensional Array:\n"; foreach ($employees as $employee) { foreach ($employee as $key => $value) { echo "$key: $value | "; } echo "\n"; } // Accessing Array Elements echo "\nAccessing Array Elements:\n"; echo "First fruit: ". $fruits[0]. "\n"; echo "Student's name: ". $student["name"]. "\n"; echo "Employee 2 department: ". $employees[1]["department"]. "\n"; // Adding Elements to Array $fruits[] = "Grapes"; $student["phone"] = "123-456-7890"; echo "\nAfter Adding Elements:\n"; print_r($fruits); print_r($student); // Removing Elements from Array unset($fruits[2]); unset($student["age"]); echo "\nAfter Removing Elements:\n"; print_r($fruits); print_r($student); ?>