php-doc-en/reference/pcre/functions/preg-quote.xml
Nilgün Belma Bugüner 751d46fd60 fixed properties
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@283830 c90b9560-bf6c-de11-be94-00142212c4b1
2009-07-11 08:31:40 +00:00

151 lines
3.7 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision$ -->
<refentry xml:id="function.preg-quote" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>preg_quote</refname>
<refpurpose>Quote regular expression characters</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<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><initializer>NULL</initializer></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>
The special regular expression characters are:
<literal>. \ + * ? [ ^ ] $ ( ) { } = ! &lt; &gt; | : -</literal>
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>str</parameter></term>
<listitem>
<para>
The input string.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>delimiter</parameter></term>
<listitem>
<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>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the quoted string.
</para>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<para>
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>5.3.0</entry>
<entry>
The <literal>-</literal> character is now quoted
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><function>preg_quote</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$keywords = '$40 for a g3/400';
$keywords = preg_quote($keywords, '/');
echo $keywords; // returns \$40 for a g3\/400
?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>Italicizing a word within some text</title>
<programlisting role="php">
<![CDATA[
<?php
// 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>
<refsect1 role="notes">
&reftitle.notes;
&note.bin-safe;
</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
-->