Closing Bug #5833: ereg_replace fails to use correct variable type.

Noted that the $regs parameter to ereg() is limited to 10 elements.


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@30437 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Torben Wilson 2000-08-18 11:16:14 +00:00
parent 359a10b20f
commit 535a1f95e4

View file

@ -106,13 +106,22 @@ $string = ereg_replace ("\n", "", $string);
the substring starting at the second, and so on. $regs[0] will
contain a copy of <parameter>string</parameter>.
</simpara>
<para>
<simpara>
If <function>ereg</function> finds any matches at all, $regs 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, $regs will not be
altered by <function>ereg</function>.
</simpara>
<simpara>
Searching is case sensitive.
</para>
<para>
Returns true if a match for pattern was found in string, or false
if no matches were found or an error occurred.
</para>
</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:
@ -127,11 +136,11 @@ if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
</programlisting>
</example>
</para>
<para>
<simpara>
See also <function>eregi</function>,
<function>ereg_replace</function>, and
<function>eregi_replace</function>.
</para>
</simpara>
</refsect1>
</refentry>
@ -150,17 +159,17 @@ if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
<paramdef>string <parameter>string</parameter></paramdef>
</funcprototype>
</funcsynopsis>
<para>
<simpara>
This function scans <parameter>string</parameter> for matches to
<parameter>pattern</parameter>, then replaces the matched text
with <parameter>replacement</parameter>.
</para>
<para>
</simpara>
<simpara>
The modified string is returned. (Which may mean that the
original string is returned if there are no matches to be
replaced.)
</para>
<para>
</simpara>
<simpara>
If <parameter>pattern</parameter> contains parenthesized
substrings, <parameter>replacement</parameter> may contain
substrings of the form
@ -170,11 +179,11 @@ if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
contents of string. Up to nine substrings may be used.
Parentheses may be nested, in which case they are counted by the
opening parenthesis.
</para>
<para>
</simpara>
<simpara>
If no matches are found in <parameter>string</parameter>, then
<parameter>string</parameter> will be returned unchanged.
</para>
</simpara>
<para>
For example, the following code snippet prints "This was a test"
three times:
@ -189,9 +198,34 @@ echo ereg_replace ("(( )is)", "\\2was", $string);
</example>
</para>
<para>
One thing to take note of is that if you use an integer value as
the <parameter>replacement</parameter> parameter, you may not get
the results you expect. This is because
<function>ereg_replace</function> will interpret the number as
the ordinal value of a character, and apply that. For instance:
<example>
<title><function>ereg_replace</function> Example</title>
<programlisting>
&lt;?php
/* This will not work as expected. */
$num = 4;
$string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has words.' */
/* This will work. */
$num = '4';
$string = "This string has four words.";
$string = ereg_replace('four', $num, $string);
echo $string; /* Output: 'This string has 4 words.' */
?>
</programlisting>
</example>
</para>
<simpara>
See also <function>ereg</function>, <function>eregi</function>,
and <function>eregi_replace</function>.
</para>
</simpara>
</refsect1>
</refentry>