bestbuildpc: Forums
 

 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Convert and Replace Old Code
 
 
Post new topic   Reply to topic    bestbuildpc Forum Index -> RavenNuke -> Tutorials
View previous topic :: View next topic  
Author Message
bestbuildpc
Site Admin
Site Admin


Joined: Jun 30, 2012
Posts: 213
Location: NL

PostPosted: Fri Nov 22, 2013 12:13    Post subject: Convert and Replace Old Code Reply with quote

Converting and replacing old code with Single Quotes, Commas and backticks

OLD

Code:
<?php echo("<strong>"._BLOG_TITLE."</strong>"); ?><br />


NEW

Code:
<?php echo('<strong>' , _BLOG_TITLE , '</strong>'); ?><br />


OLD

Code:
      echo("<option value=\"".$row[mood_id]."\" SELECTED>".$mood_title."</option>\n");

   } else {
      echo("<option value=\"".$row[mood_id]."\">".$mood_title."</option>\n");


NEW

Code:
      echo('<option value="' , $row[mood_id] , '" SELECTED>' , $mood_title , '</option>' , PHP_EOL);

   } else {
      echo('<option value="' , $row[mood_id] , '">' , $mood_title , '</option>' , PHP_EOL);


OLD

Code:
$sql = "SELECT mood_id,mood_title FROM ".$prefix."_blog_moods ORDER BY mood_title";


NEW

Code:
$sql = 'SELECT `mood_id`,`mood_title` FROM `' . $prefix . '_blog_moods` ORDER BY `mood_title`';
  
Back to top
View user's profile Send private message Visit poster's website
bestbuildpc
Site Admin
Site Admin


Joined: Jun 30, 2012
Posts: 213
Location: NL

PostPosted: Fri Nov 22, 2013 12:29    Post subject: Reply with quote

PHP only interprets escaped characters (with the exception of the escaped backslash \\ and the escaped single quote \') when in double quotes (")

This works (results in a newline):

Code:
"\n"  //GOOD but OLD


This does not result in a newline:

Code:
'\n' //NOT GOOD and WRONG


and

WRONG and OLD

Code:
$unit1 = 'paragrahp1';

$unit2 = 'paragrahp2';
echo '<p>' . $unit1 . '</p>\n';
echo '<p>' . $unit2 . '</p>';


OLD and GOOD

Code:
$unit1 = 'paragrahp1';

$unit2 = 'paragrahp2';
echo '<p>' . $unit1 . "</p>\n";
echo '<p>' . $unit2 . '</p>';


NEW and the BEST

Code:
$unit1 = 'paragrahp1';

$unit2 = 'paragrahp2';
echo '<p>' , $unit1 , '</p>' , PHP_EOL;
echo '<p>' , $unit2 , '</p>' , PHP_EOL;



Learning

When do I use the PHP constant “PHP_EOL”?

PHP_EOL is ostensibly used to find the newline character in a cross-platform-compatible way, so it handles DOS/Mac/Unix issues.

Should it be used as the end-line character when writing a command-line script?

Yes it should!!


What is the benefit of \n and PHP_EOL in PHP?

A web browser interprets the output of a PHP program as HTML, so \n and \r\n will not appear to do anything, just like inserting a newline in an HTML file.
On the other hand, <br /> makes a new line in the interpreted HTML (hence "line BReak").
Therefore, <br /> will make new lines, whereas \r\n will not do anything.


OLD
Code:
echo("\n");


NEW

Code:
echo PHP_EOL;


OLD

Code:
echo("<td align=\"center\" bgcolor=\"".$bgcolor2."\"><a href=\"" . $self . "&op=author_list\">" . _AUTHOR_LIST . "</a></td>\n");


NEW

Code:
echo '<td align="center" bgcolor="', $bgcolor2, '"><a href="', $self, '&op=author_list">', _AUTHOR_LIST, '</a></td>', PHP_EOL; 
  
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic    bestbuildpc Forum Index -> RavenNuke -> Tutorials All times are GMT + 2 Hours
 
 Page 1 of 1

 

Jump to:   
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001-2008 phpBB Group
 
Forums ©