Write less PHP code

Tags: , ,

I found a funny but working way to write less php and more html code..

Instead of writing:

<?php
	echo '< form action="" method="post">';
	echo '< input type="text" name="something">';
	echo '< /form>';
?>

We could write:

<?php { ?>
	< form action="" method="post">
	< input type="text" name="something">
	< /form>
<?php } ?>

Or maybe instead of this if – else method:

<?php
if ($something == $value) {
	echo '< div class="ok">The value is the same as $something< /div>';
} else {
	echo '< div class="ko">The value is NOT the same as $something< /div>';
}
?>

We could use:

<?php if ($something == $value): ?>
	< div class="ok">< /div>
<?php else: ?>
	< div class="ko">< /div>
<?php endif; ?>
If you liked this post think about subscribing to my RSS feed and prevent missing anything interesting. It's free, fast and doesn't hurt. Promise. Click here.
Related posts: