mirror of
https://github.com/WordPress/WordPress-Coding-Standards.git
synced 2026-07-31 14:06:59 +08:00
35 lines
1 KiB
XML
35 lines
1 KiB
XML
<?xml version="1.0"?>
|
|
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
|
|
title="Preg Quote Delimiter"
|
|
>
|
|
<standard>
|
|
<![CDATA[
|
|
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.
|
|
]]>
|
|
</standard>
|
|
<code_comparison>
|
|
<code title="Valid: The delimiter parameter is passed.">
|
|
<![CDATA[
|
|
// $input = 'my #1 fan!';
|
|
$quoted_input = preg_quote( $input, <em>'#'</em> );
|
|
preg_match(
|
|
<em>'#^' . $quoted_input . '#i'</em>,
|
|
$post_content,
|
|
$matches
|
|
);
|
|
]]>
|
|
</code>
|
|
<code title="Invalid: The delimiter parameter is missing.">
|
|
<![CDATA[
|
|
// $input = 'my #1 fan!';
|
|
$quoted_input = preg_quote( $input<em></em> );
|
|
preg_match(
|
|
<em>'#^' . $quoted_input . '#i'</em>,
|
|
$post_content,
|
|
$matches
|
|
);
|
|
]]>
|
|
</code>
|
|
</code_comparison>
|
|
</documentation>
|