vrana Tue Oct 12 03:49:13 2004 EDT
Modified files: /phpdoc/en/reference/pcre/functions preg-match-all.xml preg-match.xml Log: offset VS substr (patch by Andrey Demenev) http://cvs.php.net/diff.php/phpdoc/en/reference/pcre/functions/preg-match-all.xml?r1=1.14&r2=1.15&ty=u Index: phpdoc/en/reference/pcre/functions/preg-match-all.xml diff -u phpdoc/en/reference/pcre/functions/preg-match-all.xml:1.14 phpdoc/en/reference/pcre/functions/preg-match-all.xml:1.15 --- phpdoc/en/reference/pcre/functions/preg-match-all.xml:1.14 Tue Aug 10 12:30:20 2004 +++ phpdoc/en/reference/pcre/functions/preg-match-all.xml Tue Oct 12 03:49:05 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.14 $ --> +<!-- $Revision: 1.15 $ --> <!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 --> <refentry id="function.preg-match-all"> <refnamediv> @@ -131,13 +131,23 @@ <para> Normally, the search starts from the beginning of the subject string. The optional parameter <parameter>offset</parameter> can be used to specify - the alternate place from which to start the search. It is equivalent to - passing <function>substr</function>($subject, $offset) to - <function>preg_match</function> in place of the subject string. + the alternate place from which to start the search. The <parameter>offset</parameter> parameter is available since PHP 4.3.3. </para> + <note> + <para> + Using <parameter>offset</parameter> is not equivalent to + passing <function>substr</function>($subject, $offset) to + <function>preg_match</function> in place of the subject string, because + <parameter>pattern</parameter> can contain assertions such as + <emphasis>^</emphasis>, <emphasis>$</emphasis> or + <emphasis>(?<=x)</emphasis>. See <function>preg_match</function> for + examples. + </para> + </note> + <para> Returns the number of full pattern matches (which might be zero), or &false; if an error occurred. http://cvs.php.net/diff.php/phpdoc/en/reference/pcre/functions/preg-match.xml?r1=1.15&r2=1.16&ty=u Index: phpdoc/en/reference/pcre/functions/preg-match.xml diff -u phpdoc/en/reference/pcre/functions/preg-match.xml:1.15 phpdoc/en/reference/pcre/functions/preg-match.xml:1.16 --- phpdoc/en/reference/pcre/functions/preg-match.xml:1.15 Tue Aug 10 12:30:20 2004 +++ phpdoc/en/reference/pcre/functions/preg-match.xml Tue Oct 12 03:49:06 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.15 $ --> +<!-- $Revision: 1.16 $ --> <!-- splitted from ./en/functions/pcre.xml, last change in rev 1.2 --> <refentry id="function.preg-match"> <refnamediv> @@ -51,12 +51,71 @@ <para> Normally, the search starts from the beginning of the subject string. The optional parameter <parameter>offset</parameter> can be used to specify - the alternate place from which to start the search. It is equivalent to - passing <function>substr</function>($subject, $offset) to - <function>preg_match</function> in place of the subject string. + the alternate place from which to start the search. The <parameter>offset</parameter> parameter is available since PHP 4.3.3. </para> + <note> + <para> + Using <parameter>offset</parameter> is not equivalent to + passing <function>substr</function>($subject, $offset) to + <function>preg_match</function> in place of the subject string, because + <parameter>pattern</parameter> can contain assertions such as + <emphasis>^</emphasis>, <emphasis>$</emphasis> or + <emphasis>(?<=x)</emphasis>. Compare: + </para> + <informalexample> + <programlisting role="php"> +<![CDATA[ +<?php +$subject = "abcdef"; +$pattern = '/^def/'; +preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3); +print_r($matches); +?> +]]> + </programlisting> + <para> + will produce + </para> + <screen> +<![CDATA[ +Array +( +) +]]> + </screen> + <para> + and + </para> + <programlisting role="php"> +<![CDATA[ +<?php +$subject = "abcdef"; +$pattern = '/^def/'; +preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE); +print_r($matches); +?> +]]> + </programlisting> + <para> + will produce + </para> + <screen> +<![CDATA[ +Array +( + [0] => Array + ( + [0] => def + [1] => 0 + ) + +) +]]> + </screen> + </informalexample> + </note> <para> <function>preg_match</function> returns the number of times