svn: /phpdoc/en/trunk/ appendices/migration70/new-features.xml reference/pcre/functions/preg-replace-callback-array.xml
| From: | Adam Harvey | Date: | Mon, 21 Sep 2015 12:17:02 +0000 |
| Subject: | svn: /phpdoc/en/trunk/ appendices/migration70/new-features.xml reference/pcre/functions/preg-replace-callback-array.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13748@lists.php.net to get a copy of this message | ||
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;