Page 321 - Computer Software Application TP - Volume 1
P. 321
COMPUTER SOFTWARE APPLICATION - CITS
TASK 3 : Using PCRE Functions
I Using preg_match() for Simple Matching
1 Open the text editor
2 Write the following codes
<html >
<head>
<title> Using preg_match() </title>
</head>
<body>
<?php
$string = “My phone number is 123-456-7890.”;
$pattern = “/\b\d{3}-\d{3}-\d{4}\b/”;
if (preg_match($pattern, $string, $matches))
{
echo “Phone number found: “ . $matches[0]; // Output: 123-456-7890
}
else
{
echo “No phone number found.”;
}
?>
</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
306
CITS : IT & ITES - Computer Software Application - Exercise 58 CITS : IT & ITES - Computer Software Application - Exercise 58