Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning Regular Expressions 2005.pdf
Скачиваний:
95
Добавлен:
17.08.2013
Размер:
25.42 Mб
Скачать

PHP and Regular Expressions

So the test for the if statement returns True. The user is informed that there is a non-numeric character in $sequenceToMatch2, whose value is displayed to the user:

if ($nonNumMatch)

{

echo “<p>A non-numeric character was found in $sequenceToMatch2.</p>”;

}

else

{

echo “<p>All characters were numeric in $sequenceToMatch2.</p>”;

}

Documenting PHP Regular Expressions

The x matching modifier can be used to cause the matching engine to ignore whitespace in the regular expression that is the first argument to a function — for example, the preg_match() function.

Try It Out

Using the x Matching Modifier in Documentation

1.Type the following code in a text editor:

<html>

<head>

<title>The x matching modifier in use.</title> </head>

<body>

<?php

$US_SSN = “123-12-1234”; $myMatch = preg_match(“/

\d{3} # Matches three numeric digits

-# Matches a literal hyphen \d{2} # Matches two numeric digits

-# Matches a literal hyphen \d{4} # Matches four numeric digits

/x”, “123-12-1234”, $theMatch);

echo “<p>The test string was: ‘$US_SSN’.</p>”;

echo “<p>This matches the pattern /\d{3}-\d{2}-\d{4}/</p>”; ?>

</body>

</html>

2.Save the code as C:\inetpub\wwwroot\PHP\XModifier.php.

3.In Internet Explorer, enter the URL http://localhost/PHP/XModifier.php, and inspect the results displayed, as shown in Figure 23-24.

589