Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Q4.

For this exercise, write a script using the following variable:


$txt= “He opened the file and saw that there were only thirty visible light images and twelve
radar images of Deimos”;
$str= “images”;
$rplc= “problems”;
$numofchars=10;
$occr=”f”

The script will display the following output:

The text is “He opened the file and saw that there were only thirty visible light images and
twelve radar images of Deimos”

The text includes “35” vowels.

The text is formed from “20” words.

When we replace “images” with “problems” the text becomes “He opened the file and saw
that there were only thirty visible light problems and twelve radar problems of Deimos”

The first 10 characters of the string are: “He opened “

The last 10 characters of the string are: “ of Deimos”

The first occurance of “f” is “15”. character.

The uppercase version of the is: “HE OPENED THE FILE AND SAW THAT THERE WERE ONLY
THIRTY VISIBLE LIGHT IMAGES AND TWELVE RADAR IMAGES OF DEIMOS”

<?php

$txt= "“He opened the file and saw that there were only thirty visible light images and twelve radar images of Deimos”";
$str= "images";
$rplc= "problems";
$numofchars=10;
$occr="f";
echo "The text is ".$txt;
echo "<br><br>The text includes “".preg_match_all('/[aeiou]/i',$txt,$matches)."” vowels.";
echo "<br><br>The text is formed from “".strlen($txt)."” words.";
echo "<br><br>When we replace “".$str."” with “".$rplc."” the text becomes ".str_replace($str,$rplc,$txt);
echo "<br><br>The first “".$numofchars."” characters of the string are: “".substr($txt,$numofchars);
echo "<br><br>The last “".$numofchars."” characters of the string are: “".substr($txt,-2*$numofchars);
echo "<br><br>The first occurance of “".$occr."” is “".substr_count($txt, $occr)."”. character.";
echo "<br><br>The uppercase version of the is: “".strtoupper($txt);
?>

You might also like