Skip to content

Commit

Permalink
Document DOMXPath::quote() (php#3909)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos authored Oct 23, 2024
1 parent f023171 commit bac9d6a
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
127 changes: 127 additions & 0 deletions reference/dom/domxpath/quote.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="domxpath.quote" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>DOMXPath::quote</refname>
<refpurpose>
Quotes a string for use in an XPath expression
</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="DOMXPath">
<modifier>public</modifier> <modifier>static</modifier> <type>string</type><methodname>DOMXPath::quote</methodname>
<methodparam><type>string</type><parameter>str</parameter></methodparam>
</methodsynopsis>
<simpara>
Quotes <parameter>str</parameter> for use in an XPath expression.
</simpara>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>str</parameter></term>
<listitem>
<simpara>
The string to quote.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<simpara>
Returns a quoted string to be used in an XPath expression.
</simpara>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Matching attribute value with quotes</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument;
$doc->loadXML(<<<XML
<books>
<book name="'quoted' name">Book title</book>
</books>
XML);
$xpath = new DOMXPath($doc);
$query = "//book[@name=" . DOMXPath::quote("'quoted' name") . "]";
echo $query, "\n";
$entries = $xpath->query($query);
foreach ($entries as $entry) {
echo "Found ", $entry->textContent, "\n";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
//book[@name="'quoted' name"]
Found Book title
]]>
</screen>
<simpara>
Mixed quote types are also supported:
</simpara>
<programlisting role="php">
<![CDATA[
<?php
echo DOMXPath::quote("'different' \"quote\" styles");
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
concat("'different' ",'"quote" styles')
]]>
</screen>
</example>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>DOMXPath::evaluate</methodname></member>
<member><methodname>DOMXPath::query</methodname></member>
</simplelist>
</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:"~/.phpdoc/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
-->
1 change: 1 addition & 0 deletions reference/dom/versions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
<function name="domxpath::query" from="PHP 5, PHP 7, PHP 8"/>
<function name="domxpath::registernamespace" from="PHP 5, PHP 7, PHP 8"/>
<function name="domxpath::registerphpfunctions" from="PHP 5 &gt;= 5.3.0, PHP 7, PHP 8"/>
<function name="domxpath::quote" from="PHP 8 &gt;= 8.4.0"/>

<function name="dom_import_simplexml" from="PHP 5, PHP 7, PHP 8"/>

Expand Down

0 comments on commit bac9d6a

Please sign in to comment.