Page 322 - Computer Software Application TP - Volume 1
P. 322
COMPUTER SOFTWARE APPLICATION - CITS
II Using preg_match_all() for Multiple Matches
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Using preg_match_all()</title>
</head>
<body>
<?php
$str = “The rain in SPAIN falls mainly on the plains.”;
$pattern = “/ain/i”;
echo preg_match_all($pattern, $str);
?>
</body>
</html>
3 Save the program in C:\Apache24\htdocs in a folder with .php extension
4 Run the Apache services from windows services
5 Open the browser and type the following address
http://localhost/foldername/
6 Click the php file to run and verify the output
III Using preg_replace() for Replacement
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Using preg_replace() </title>
</head>
<body>
<?php
$str = “Visit Microseft!”;
$pattern = “/microsoft/i”;
echo preg_replace($pattern, “Google”, $str);
307
CITS : IT & ITES - Computer Software Application - Exercise 58