Skip to content

Commit 2f331db

Browse files
authored
Merge pull request #2677 from rodrigoprimo/docs-preg-quote-delimiter
PHP/PregQuoteDelimiter: add XML documentation
2 parents f48a181 + fae2dc0 commit 2f331db

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+
title="Preg Quote Delimiter"
5+
>
6+
<standard>
7+
<![CDATA[
8+
Passing the $delimiter parameter to `preg_quote()` is strongly recommended to ensure the regular expression delimiter is properly escaped if it occurs in the input string.
9+
]]>
10+
</standard>
11+
<code_comparison>
12+
<code title="Valid: The delimiter parameter is passed.">
13+
<![CDATA[
14+
// $input = 'my #1 fan!';
15+
$quoted_input = preg_quote( $input, <em>'#'</em> );
16+
preg_match(
17+
<em>'#^' . $quoted_input . '#i'</em>,
18+
$post_content,
19+
$matches
20+
);
21+
]]>
22+
</code>
23+
<code title="Invalid: The delimiter parameter is missing.">
24+
<![CDATA[
25+
// $input = 'my #1 fan!';
26+
$quoted_input = preg_quote( $input<em></em> );
27+
preg_match(
28+
<em>'#^' . $quoted_input . '#i'</em>,
29+
$post_content,
30+
$matches
31+
);
32+
]]>
33+
</code>
34+
</code_comparison>
35+
</documentation>

0 commit comments

Comments
 (0)