<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Smarty &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/smarty/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>PHP if-else-endif Statements</title>
		<link>/2010/03/10/php-if-else-endif-statements/</link>
		<comments>/2010/03/10/php-if-else-endif-statements/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 08:12:22 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Bracket]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Cross-platform software]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Smarty]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[template systems]]></category>
		<category><![CDATA[typical web developer]]></category>

		<guid isPermaLink="false">/?p=1221</guid>
		<description><![CDATA[PHP: if A typical web developer knows exactly how a PHP if statement looks like: if ( expression ) { // if the expression was true proceed here } else { // there was a false expression } HTML mess with PHP When it comes to merge PHP and HTML the things are becoming ugly. &#8230; <a href="/2010/03/10/php-if-else-endif-statements/" class="more-link">Continue reading <span class="screen-reader-text">PHP if-else-endif Statements</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/04/26/php-strings-dont-need-quotes/" rel="bookmark" title="PHP Strings Don&#8217;t Need Quotes">PHP Strings Don&#8217;t Need Quotes </a></li>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/05/25/php-coding-style-large-if-statements/" rel="bookmark" title="PHP Coding Style: Large IF Statements">PHP Coding Style: Large IF Statements </a></li>
<li><a href="/2010/02/07/javascript-optimization-optimizing-if-statements/" rel="bookmark" title="JavaScript optimization. Optimizing IF statements.">JavaScript optimization. Optimizing IF statements. </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>PHP: if</h2>
<p>A typical web developer knows exactly how a PHP if statement looks like:</p>
<pre lang="php">   if ( expression ) {
      // if the expression was true proceed here
   } else {
      // there was a false expression
  }
</pre>
<h2>HTML mess with PHP</h2>
<p>When it comes to merge PHP and HTML the things are becoming ugly. Indeed most of the template systems as Smarty are improved and developed to overcome this issue, however when working with a native PHP code with no template system or with template system where the PHP code is allowed the things are really bad.</p>
<p>Let me show this in a breve example. Image you have to show different formatted HTML depending on a PHP expression. Something like that</p>
<pre lang="php">
<?php if (expression) { ?>
<div class="message">OK. Your registration is successful</div>
<?php } else { ?>
<div class="error">Something went wrong! Please try again later! </div>
<?php } ?>
</pre>
<p>Now you can see how difficult to maintain this code is when it doesn&#8217;t make use of only one code of HTML markup. Imaging you&#8217;ve to print differently formatted tables! Indeed the PHP curly brackets are different to follow.</p>
<h2>PHP: the different IF syntax</h2>
<p>So there is a PHP syntax that tries to help you manage this. You can write more human readable code like this:</p>
<pre lang="php">
<?php if ( expression ) : ?>
<div>message goes here</div>
<?php endif ?>
</pre>
<p>Thus you get the ENDIF instead of only one curly bracket. That&#8217;s indeed readable enough. In fact you can use this syntax with any conditional or loop statement in PHP:</p>
<pre lang="php">
<?php foreach($array as $key => $val) : ?>
<div class="message"><?php echo $val ?></div><br />
<?php endforeach ?>
</pre>
<p>To return in the previous example the code above should be transformed in that:</p>
<pre lang="php">
<?php if ( expression ) : ?>
<div class="message">some message here!</div>
<?php else : ?>
<div class="error">some error here!</div>
<?php endif ?>
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/04/26/php-strings-dont-need-quotes/" rel="bookmark" title="PHP Strings Don&#8217;t Need Quotes">PHP Strings Don&#8217;t Need Quotes </a></li>
<li><a href="/2010/05/19/php-associative-arrays-coding-style/" rel="bookmark" title="PHP Associative Arrays Coding Style">PHP Associative Arrays Coding Style </a></li>
<li><a href="/2010/05/25/php-coding-style-large-if-statements/" rel="bookmark" title="PHP Coding Style: Large IF Statements">PHP Coding Style: Large IF Statements </a></li>
<li><a href="/2010/02/07/javascript-optimization-optimizing-if-statements/" rel="bookmark" title="JavaScript optimization. Optimizing IF statements.">JavaScript optimization. Optimizing IF statements. </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/10/php-if-else-endif-statements/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
