svn: /phpdoc/en/trunk/reference/tokenizer/functions/ token-get-all.xml
| From: | Thomas Punt | Date: | Thu, 24 Dec 2015 10:42:14 +0000 |
| Subject: | svn: /phpdoc/en/trunk/reference/tokenizer/functions/ token-get-all.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13933@lists.php.net to get a copy of this message | ||
tpunt Thu, 24 Dec 2015 10:42:14 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=338346
Log:
Cleanup the token_get_all() man page
Changed paths:
U phpdoc/en/trunk/reference/tokenizer/functions/token-get-all.xml
Modified: phpdoc/en/trunk/reference/tokenizer/functions/token-get-all.xml
===================================================================
--- phpdoc/en/trunk/reference/tokenizer/functions/token-get-all.xml 2015-12-24 10:23:32 UTC (rev
338345)
+++ phpdoc/en/trunk/reference/tokenizer/functions/token-get-all.xml 2015-12-24 10:42:14 UTC (rev
338346)
@@ -63,34 +63,98 @@
content of the original token in element 1 and the line number in element 2.
</para>
</refsect1>
+ <refsect1 role="changelog">
+ &reftitle.changelog;
+ <para>
+ <informaltable>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>&Version;</entry>
+ <entry>&Description;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>7.0.0</entry>
+ <entry>
+ Added the optional <parameter>flags</parameter> parameter along with
+ the <constant>TOKEN_PARSE</constant> flag.
+ </entry>
+ </row>
+ <row>
+ <entry>5.2.2</entry>
+ <entry>
+ Line numbers are returned in element 2
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+ </para>
+ </refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
- <title><function>token_get_all</function> examples</title>
+ <title><function>token_get_all</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
-$tokens = token_get_all('<?php echo; ?>'); /* => array(
- array(T_OPEN_TAG, '<?php'),
- array(T_ECHO, 'echo'),
- ';',
- array(T_CLOSE_TAG, '?>') ); */
+$tokens = token_get_all('<?php echo; ?>');
-/* Note in the following example that the string is parsed as T_INLINE_HTML
- rather than the otherwise expected T_COMMENT (T_ML_COMMENT in PHP <5).
- This is because no open/close tags were used in the "code" provided.
- This would be equivalent to putting a comment outside of <?php ?> tags in a normal file.
*/
-$tokens = token_get_all('/* comment */'); // => array(array(T_INLINE_HTML, '/*
comment */'));
+foreach ($tokens as $token) {
+ if (is_array($token)) {
+ echo "Line {$token[2]}: ", token_name($token[0]), "
('{$token[1]}')", PHP_EOL;
+ }
+}
?>
]]>
</programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+Line 1: T_OPEN_TAG ('<?php ')
+Line 1: T_ECHO ('echo')
+Line 1: T_WHITESPACE (' ')
+Line 1: T_CLOSE_TAG ('?>')
+]]>
+ </screen>
</example>
</para>
<para>
<example>
+ <title><function>token_get_all</function> incorrect usage
example</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+$tokens = token_get_all('/* comment */');
+
+foreach ($tokens as $token) {
+ if (is_array($token)) {
+ echo "Line {$token[2]}: ", token_name($token[0]), "
('{$token[1]}')", PHP_EOL;
+ }
+}
+?>
+]]>
+ </programlisting>
+ &example.outputs.similar;
+ <screen>
+<![CDATA[
+Line 1: T_INLINE_HTML ('/* comment */')
+]]>
+ </screen>
+ </example>
+ Note in the previous example that the string is parsed as
+ <constant>T_INLINE_HTML</constant> rather than the expected
+ <constant>T_COMMENT</constant>. This is because no open tag was used in the
+ code provided. This would be equivalent to putting a comment outside of the
+ PHP tags in a normal file.
+ </para>
+ <para>
+ <example>
<title>
- <function>token_get_all</function> on class using a reserved word
+ <function>token_get_all</function> on a class using a reserved word example
</title>
<programlisting role="php">
<![CDATA[
@@ -135,34 +199,13 @@
<constant>T_PUBLIC</constant>.
</para>
</refsect1>
- <refsect1 role="changelog">
- &reftitle.changelog;
+
+ <refsect1 role="seealso">
+ &reftitle.seealso;
<para>
- <informaltable>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>&Version;</entry>
- <entry>&Description;</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>7.0.0</entry>
- <entry>
- Added the optional <parameter>flags</parameter> parameter along with
- the <constant>TOKEN_PARSE</constant> flag.
- </entry>
- </row>
- <row>
- <entry>5.2.2</entry>
- <entry>
- Line numbers are returned in element 2
- </entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
+ <simplelist>
+ <member><function>token_name</function></member>
+ </simplelist>
</para>
</refsect1>
</refentry>