[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-cvs
Subject:    [DOC-CVS] =?utf-8?q?svn:_/phpdoc/en/trunk/_appendices/migration70/new-features.xml_reference/pcre/fu
From:       Adam_Harvey <aharvey () php ! net>
Date:       2015-09-21 12:17:02
Message-ID: svn-aharvey-1442837822-337869-416387637 () svn ! php ! net
[Download RAW message or body]

aharvey                                  Mon, 21 Sep 2015 12:17:02 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=337869

Log:
Cut down the preg_replace_callback_array() part of the migration guide.

I've removed the example: it was terrific, but the function reference has a
good example, and it was much too long for the page.

Changed paths:
    U   phpdoc/en/trunk/appendices/migration70/new-features.xml
    U   phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback-array.xml

Modified: phpdoc/en/trunk/appendices/migration70/new-features.xml
===================================================================
--- phpdoc/en/trunk/appendices/migration70/new-features.xml	2015-09-21 12:16:57 UTC \
                (rev 337868)
+++ phpdoc/en/trunk/appendices/migration70/new-features.xml	2015-09-21 12:17:02 UTC \
(rev 337869) @@ -623,15 +623,14 @@
  </sect2>

  <sect2 xml:id="migration70.new-features.preg-repace-callback-array-function">
-  <title><function>preg_replace_callback_array</function> Function</title>
+  <title><function>preg_replace_callback_array</function></title>

   <para>
-   This new function enables code to be written more cleanly when using the
+   The new <function>preg_replace_callback_array</function> function enables
+   code to be written more cleanly when using the
    <function>preg_replace_callback</function> function. Prior to PHP 7,
    callbacks that needed to be executed per regular expression required the
-   callback function (second parameter of
-   <function>preg_replace_callback</function>) to be polluted with lots of
-   branching (a hacky method at best).
+   callback function to be polluted with lots of branching.
   </para>

   <para>
@@ -639,78 +638,8 @@
    associative array, where the key is a regular expression and the value is a
    callback.
   </para>
-
-  <para>
-   Function Signature:
-  </para>
-
-  <programlisting>
-<![CDATA[
-string preg_replace_callback_array(array $regexesAndCallbacks, string $input);
-]]>
-  </programlisting>
-
-  <informalexample>
-   <programlisting role="php">
-<![CDATA[
-<?php
-
-$tokenStream = []; // [tokenName, lexeme] pairs
-
-$input = <<<'end'
-$a = 3; // variable initialisation
-end;
-
-// Pre PHP 7 code
-preg_replace_callback(
-    [
-        '~\$[a-z_][a-z\d_]*~i',
-        '~=~',
-        '~[\d]+~',
-        '~;~',
-        '~//.*~'
-    ],
-    function ($match) use (&$tokenStream) {
-        if (strpos($match[0], '$') === 0) {
-            $tokenStream[] = ['T_VARIABLE', $match[0]];
-        } elseif (strpos($match[0], '=') === 0) {
-            $tokenStream[] = ['T_ASSIGN', $match[0]];
-        } elseif (ctype_digit($match[0])) {
-            $tokenStream[] = ['T_NUM', $match[0]];
-        } elseif (strpos($match[0], ';') === 0) {
-            $tokenStream[] = ['T_TERMINATE_STMT', $match[0]];
-        } elseif (strpos($match[0], '//') === 0) {
-            $tokenStream[] = ['T_COMMENT', $match[0]];
-        }
-    },
-    $input
-);
-
-// PHP 7+ code
-preg_replace_callback_array(
-    [
-        '~\$[a-z_][a-z\d_]*~i' => function ($match) use (&$tokenStream) {
-            $tokenStream[] = ['T_VARIABLE', $match[0]];
-        },
-        '~=~' => function ($match) use (&$tokenStream) {
-            $tokenStream[] = ['T_ASSIGN', $match[0]];
-        },
-        '~[\d]+~' => function ($match) use (&$tokenStream) {
-            $tokenStream[] = ['T_NUM', $match[0]];
-        },
-        '~;~' => function ($match) use (&$tokenStream) {
-            $tokenStream[] = ['T_TERMINATE_STMT', $match[0]];
-        },
-        '~//.*~' => function ($match) use (&$tokenStream) {
-            $tokenStream[] = ['T_COMMENT', $match[0]];
-        }
-    ],
-    $input
-);
-]]>
-   </programlisting>
-  </informalexample>
  </sect2>
+
  <sect2 xml:id="migration70.new-features.csprng-functions">
   <title><link linkend="book.csprng">CSPRNG</link> Functions</title>


Modified: phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback-array.xml
===================================================================
--- phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback-array.xml	2015-09-21 \
                12:16:57 UTC (rev 337868)
+++ phpdoc/en/trunk/reference/pcre/functions/preg-replace-callback-array.xml	2015-09-21 \
12:17:02 UTC (rev 337869) @@ -99,6 +99,7 @@
     ],
     $subject
 );
+?>
 ]]>
     </programlisting>
     &example.outputs;



-- 
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic