mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-19 18:38:55 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78496 c90b9560-bf6c-de11-be94-00142212c4b1
82 lines
2.6 KiB
XML
82 lines
2.6 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision: 1.2 $ -->
|
|
<!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 -->
|
|
<refentry id="function.preg-quote">
|
|
<refnamediv>
|
|
<refname>preg_quote</refname>
|
|
<refpurpose>Quote regular expression characters</refpurpose>
|
|
</refnamediv>
|
|
<refsect1>
|
|
<title>Description</title>
|
|
<methodsynopsis>
|
|
<type>string</type><methodname>preg_quote</methodname>
|
|
<methodparam><type>string</type><parameter>str</parameter></methodparam>
|
|
<methodparam choice="opt"><type>string</type><parameter>delimiter</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
<function>preg_quote</function> takes <parameter>str</parameter>
|
|
and puts a backslash in front of every character that is part of
|
|
the regular expression syntax. This is useful if you have a
|
|
run-time string that you need to match in some text and the
|
|
string may contain special regex characters.
|
|
</para>
|
|
<para>
|
|
If the optional <parameter>delimiter</parameter> is specified, it
|
|
will also be escaped. This is useful for escaping the delimiter
|
|
that is required by the PCRE functions. The / is the most commonly
|
|
used delimiter.</para>
|
|
<para>
|
|
The special regular expression characters are:
|
|
<screen>. \\ + * ? [ ^ ] $ ( ) { } = ! < > | :</screen>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
$keywords = "$40 for a g3/400";
|
|
$keywords = preg_quote ($keywords, "/");
|
|
echo $keywords; // returns \$40 for a g3\/400
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
<example>
|
|
<title>Italicizing a word within some text</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
// In this example, preg_quote($word) is used to keep the
|
|
// asterisks from having special meaning to the regular
|
|
// expression.
|
|
|
|
$textbody = "This book is *very* difficult to find.";
|
|
$word = "*very*";
|
|
$textbody = preg_replace ("/".preg_quote($word)."/",
|
|
"<i>".$word."</i>",
|
|
$textbody);
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|