Welcome Guest, Not a member yet? Register   Sign In
View code that hurts your brain
#1

[eluser]xwero[/eluser]
I just saw this blog post and glancing over it i saw this snippet
Code:
<html>

<head>

<title><?php echo $title;?></title>

</head>

<body>

<h1>&lt;?php echo $header;?&gt;</h1>

<ul>

&lt;?php foreach($users as $user):?&gt;

<li>

<p>&lt;?php echo 'Full Name: '.$user['firstname'].' '.$user['lastname'].' Email: '.$user['email'];?&gt;</p>

</li>

&lt;?php endforeach;?&gt;

</ul>

<p>&lt;?php echo 'Total number of users :'.$numusers;?&gt;</p>

&lt;/body&gt;

&lt;/html&gt;
What make people echo strings in a view file?

My version
Code:
&lt;html&gt;

&lt;head&gt;

&lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;

&lt;/head&gt;

&lt;body&gt;

<h1>&lt;?php echo $header;?&gt;</h1>

<ul>

&lt;?php foreach($users as $user):?&gt;

<li>

<p>Full Name: &lt;?php echo $user['firstname'].' '.$user['lastname']; ?&gt; Email: &lt;?php echo $user['email'];?&gt;</p>

</li>

&lt;?php endforeach;?&gt;

</ul>

<p>Total number of users :&lt;?php echo $numusers;?&gt;</p>

&lt;/body&gt;

&lt;/html&gt;
I know many little php escapes can slow down the page rendering but this doesn't mean you have to put a paragraph in a single echo? What if you want to add html tags then it become even uglier that it is now.


Messages In This Thread
View code that hurts your brain - by El Forum - 08-22-2008, 03:32 AM
View code that hurts your brain - by El Forum - 08-22-2008, 08:22 AM
View code that hurts your brain - by El Forum - 08-22-2008, 09:42 AM
View code that hurts your brain - by El Forum - 08-22-2008, 10:45 AM
View code that hurts your brain - by El Forum - 08-22-2008, 12:37 PM
View code that hurts your brain - by El Forum - 08-22-2008, 02:28 PM
View code that hurts your brain - by El Forum - 08-22-2008, 04:10 PM
View code that hurts your brain - by El Forum - 08-22-2008, 04:42 PM
View code that hurts your brain - by El Forum - 08-22-2008, 06:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB