Practical - 5 IWD

 

Aim 1(a): Check if the given string is in lowercase

Program

<?php $string = "hello world"; if ($string === strtolower($string)) { echo "The given string is in lowercase."; } else { echo "The given string is NOT in lowercase."; } ?>


  • strtolower() converts a string to lowercase.

  • If the original string and lowercase string are the same, it means the string is already in lowercase.


Aim 1(b): Replace a given word from the given string

Program

<?php $string = "PHP is a powerful scripting language"; $search = "powerful"; $replace = "popular"; $newString = str_replace($search, $replace, $string); echo "Original String: " . $string . "<br>"; echo "Modified String: " . $newString; ?>


  • str_replace() replaces a word or part of a string with another word.

  • The function does not change the original string; it returns a new one.

Comments

Popular posts from this blog

Unit I - Introduction to PHP

Practical - 1 IWD

Practical - 10 IWD