php-doc-en/reference/regex/functions/ereg.xml
Hartmut Holzgraefe 5b9fc29465 revision tags added
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78496 c90b9560-bf6c-de11-be94-00142212c4b1
2002-04-17 06:45:35 +00:00

100 lines
3.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/regex.xml, last change in rev 1.2 -->
<refentry id="function.ereg">
<refnamediv>
<refname>ereg</refname>
<refpurpose>Regular expression match</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>int</type><methodname>ereg</methodname>
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
<methodparam><type>string</type><parameter>string</parameter></methodparam>
<methodparam choice="opt"><type>array</type><parameter>regs</parameter></methodparam>
</methodsynopsis>
<note>
<para>
<function>preg_match</function>, which uses a Perl-compatible
regular expression syntax, is often a faster alternative to
<function>ereg</function>.
</para>
</note>
<simpara>
Searches a <parameter>string</parameter> for matches to the regular
expression given in <parameter>pattern</parameter>.
</simpara>
<simpara>
If matches are found for parenthesized substrings of
<parameter>pattern</parameter> and the function is called with
the third argument <parameter>regs</parameter>, the matches will
be stored in the elements of the array
<parameter>regs</parameter>. $regs[1] will contain the substring
which starts at the first left parenthesis; $regs[2] will contain
the substring starting at the second, and so on. $regs[0] will
contain a copy of the complete string matched.
</simpara>
<note>
<simpara>
Up to (and including) PHP 4.1.0 <literal>$regs</literal> will be
filled with exactly ten elements, even though more or fewer than
ten parenthesized substrings may actually have matched. This has
no effect on <function>ereg</function>'s ability to match more
substrings. If no matches are found, <literal>$regs</literal>
will not be altered by <function>ereg</function>.
</simpara>
</note>
<simpara>
Searching is case sensitive.
</simpara>
<simpara>
Returns &true; if a match for <parameter>pattern</parameter> was
found in <parameter>string</parameter>, or &false; if no matches
were found or an error occurred.
</simpara>
<para>
The following code snippet takes a date in ISO format
(YYYY-MM-DD) and prints it in DD.MM.YYYY format:
<example>
<title><function>ereg</function> Example</title>
<programlisting role="php">
<![CDATA[
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";
} else {
echo "Invalid date format: $date";
}
]]>
</programlisting>
</example>
</para>
<simpara>
See also <function>eregi</function>,
<function>ereg_replace</function>,
<function>eregi_replace</function>, and
<function>preg_match</function>.
</simpara>
</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
-->