spasticdonkey
RavenNuke(tm) Development Team

Joined: Dec 02, 2006
Posts: 1693
Location: Texas, USA
|
Posted:
Thu Oct 04, 2012 4:05 pm |
|
Good point about isset. You can search the RN code for examples of use.
If you are including a PHP file to output HTML you could use example #3 or #4 @ the top of your files
http://rnwiki.ravennuke.com/wiki/RNTeam:Coding_Standards#File_Security
I generally don't like jumping in and out of PHP to output HTML, and prefer to use echo '';
From a code readability standpoint I don't really like seeing this, but it's just my preference..
<h2><?php echo $title; ?></h2>
better
echo '<h2>' . $title . '</h2>';
You just have to make sure to escape any single quotes, or convert them to double quotes
broken
echo '<h2 class='title'>Lamb</h2>';
echo '<h2>Mary's Lamb</h2>';
better
echo '<h2 class="title">Lamb</h2>';
echo '<h2>Mary\'s Lamb</h2>'; |
|
|
neralex
Site Admin

Joined: Aug 22, 2007
Posts: 1775
|
Posted:
Thu Oct 04, 2012 5:14 pm |
|
In all inlcuded files you don't need the php closing tag like this "?>"
Code:<?php // file starts here
echo '<h2>' . $title . '</h2>';
|
If you have some echo calls to each other, then can you use this one:
Code:echo '<h2 class"title">' , $title , '</h2>'
, '<div class"hometext">' , $hometext , '</div>'
, '<div class"bodytest">' , $bodytest , '</div>';
|
If you get an break with a function between the echo lines:
Code:echo '<h2 class"title">' , $title , '</h2>'
, _LANG_CONSTANT1 , '<br />'
, '<div class"hometext">' , $hometext , '</div>'
, '<div class"bodytest">' , $bodytest , '</div>';
test();
echo '<div class"something">' , $something , '</div>'
, _LANG_CONSTANT2 , '<br />'
, '<div class"anyway">' , $anyway , '</div>';
|
Thus you avoid you getting the same echo calls. This saves a lot of code in large scripts.
The most developers wants a clear code in the browser without have all in one line. The problem with the echo calls is, you have no linebreaks in the sourcecode view of your browser and all is in one line.
If you want now make an linebreak after the the closed divs in the sourcecode view, then you can use the constant PHP_EOL or you make double quotes. But double qoutes are not the best solution. I believe i have sent you for a while some links for the using of PHP_EOL ... any way here again a example:
line breaks with PHP_EOL:
Code:echo '<h2 class"title">' , $title , '</h2>' , PHP_EOL
, _LANG_CONSTANT , '<br />' , PHP_EOL
, '<div class"hometext">' , $hometext , '</div>' , PHP_EOL
, '<div class"bodytest">' , $bodytest , '</div>' , PHP_EOL;
|
http://youngdutchdesign.com/linebreaks-with-phpeol
http://stackoverflow.com/questions/128560/when-do-i-use-the-php-constant-php-eol
http://stackoverflow.com/questions/6810557/what-is-the-benefit-of-n-and-php-eol-in-php
or line breaks with double quotes:
Code:echo '<h2 class"title">' , $title , '</h2>' , "\n"
, _LANG_CONSTANT , '<br />' , "\n"
, '<div class"hometext">' , $hometext , '</div>' , "\n"
, '<div class"bodytest">' , $bodytest , '</div>' , "\n";
|
|
|
|