Skip to content

Commit 0670e8a

Browse files
tikifezjrfnl
authored andcommitted
PHP/PregQuoteDelimiter: add XML documentation
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
1 parent f48a181 commit 0670e8a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
$quoted_input = preg_quote( $input, <em>'#'</em> );
15+
preg_match(
16+
<em>'#^' . $quoted_input . '#i'</em>,
17+
$post_content,
18+
$matches
19+
);
20+
]]>
21+
</code>
22+
<code title="Invalid: The delimiter parameter is missing.">
23+
<![CDATA[
24+
// $input = 'my #1 fan!';
25+
$quoted_input = preg_quote( $input<em></em> );
26+
preg_match(
27+
<em>'#^' . $quoted_input . '#i'</em>,
28+
$post_content,
29+
$matches
30+
);
31+
]]>
32+
</code>
33+
</code_comparison>
34+
</documentation>

0 commit comments

Comments
 (0)