Ads 468x60px

Showing posts with label php short tags. Show all posts
Showing posts with label php short tags. Show all posts

Thursday, 18 April 2013

PHP Short Tags

PHP Short Tags

You know when you just want to prepopulate a form or add one PHP variable into the middle of a an HTML block. Well having to write an open PHP tag and then a close PHP with all of the line breaks and indentions to make it readable is such a pain. So what is the solution? PHP short tags like this.



1<?php
2    $example = 'This is some text that I want in my paragraph.';
3?>
4<html>
5    <head>
6    </head>
7    <body>
8        <h1>I love short tags</h1>
9        <p>
10        < ?php
11            echo $example;
12        ?>
13        </p>
14    </body>
15</html>
16</pre>
17Personally I like to get things done with as little typing and code as possible, so I am not a fan of this.  I love my short tags.
18<pre>
19<?php
20    $example = 'This is some text that I want in my paragraph.';
21?>
22<html>
23    <head>
24    </head>
25    <body>
26        <h1>I love short tags</h1>
27        <p>
28        < ?=$example?>
29        </p>
30    </body>
31</html>


That will produce the exact same output as the first but much neater and with a little less code.

NOTE: Short tags is something that can be disabled in the php.ini so it is not guaranteed to work but industry standard has short tags enabled.




Most Wanted Posts

Related Posts Plugin for WordPress, Blogger...