svn: /phpdoc/en/trunk/language/ basic-syntax.xml

From: Date: Wed, 14 Mar 2012 18:49:47 +0000
Subject: svn: /phpdoc/en/trunk/language/ basic-syntax.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9887@lists.php.net to get a copy of this message
drak Wed, 14 Mar 2012 18:49:47 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=324248 Log: Clarified how PHP skips over unmet conditions when using mixed PHP and non PHP content in a file. Changed paths: U phpdoc/en/trunk/language/basic-syntax.xml Modified: phpdoc/en/trunk/language/basic-syntax.xml =================================================================== --- phpdoc/en/trunk/language/basic-syntax.xml 2012-03-14 18:11:04 UTC (rev 324247) +++ phpdoc/en/trunk/language/basic-syntax.xml 2012-03-14 18:49:47 UTC (rev 324248) @@ -46,7 +46,7 @@ Everything outside of a pair of opening and closing tags is ignored by the PHP parser which allows PHP files to have mixed content. This allows PHP to be embedded in HTML documents, for example to create templates. - <informalexample> + <example> <programlisting role="php"> <![CDATA[ <p>This is going to be ignored by PHP and displayed by the browser.</p> @@ -54,37 +54,37 @@ <p>This will also be ignored by PHP and displayed by the browser.</p> ]]> </programlisting> - </informalexample> + </example> + This works as expected, because when PHP hits the ?&gt; closing + tags, it simply starts outputting whatever it finds (except for an + immediately following newline - see + <link linkend="language.basic-syntax.instruction-separation">instruction separation</link> + ) until it hits another opening tag unless PHP is in the middle of a conditional statement. See the + next example. </para> <para> - You can also use more advanced structures: + You can also use more advanced structures with conditions <example> - <title>Advanced escaping</title> + <title>Advanced escaping using conditions</title> <programlisting role="php"> <![CDATA[ -<?php -if ($expression) { - ?> - <strong>This is true.</strong> - <?php -} else { - ?> - <strong>This is false.</strong> - <?php -} -?> +<?php if( $expression == true ): ?> + This will show if the expression is true. +<?php else: ?> + Otherwise this will show. +<?php endif; ?> ]]> </programlisting> </example> - This works as expected, because when PHP hits the ?&gt; closing - tags, it simply starts outputting whatever it finds (except for an - immediately following newline - see - <link linkend="language.basic-syntax.instruction-separation">instruction separation</link> - ) until it hits - another opening tag. The example given here is contrived, of - course, but for outputting large blocks of text, dropping out of - PHP parsing mode is generally more efficient than sending all of - the text through <function>echo</function> or + In this example PHP will skip the blocks where the condition is not met, even + though they are outside of the PHP open/close tags, PHP skips them according + to the condition since the PHP interpreter will jump over blocks contained + within a condition what is not met. + </para> + <para> + The example given here is contrived, of course, but for outputting large + blocks of text, dropping out of PHP parsing mode is generally more efficient + than sending all of the text through <function>echo</function> or <function>print</function>. </para> <para>

« previous php.doc.cvs (#9887) next »