egorig Posted May 8, 2007 Share Posted May 8, 2007 Which one is the best : echo ("My name is $name"); echo "My name is $name"; echo "My name is ".$name.""; i use this ! but is it better than the previous one? Is it necessary to concatenate? echo ("My name is ".$name.""); echo "My name is "; echo $name; Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/ Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 Either one works, but the best all depends on your style. Personally my favorite would be this: <?php echo "My name is " . $name; ?> strictly because that way I know no funny business will happen to my variables. That is just how I do it. Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248314 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Share Posted May 8, 2007 Which ever works for you. Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248316 Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 honestly... its really down to personal preference... personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?> Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248317 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Share Posted May 8, 2007 honestly... its really down to personal preference... personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?> What does it do? <?php <?=$var?> ?> Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248319 Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 <?=$var?> is just a shortform for <?php echo $var?> Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248321 Share on other sites More sharing options...
The Bat Posted May 8, 2007 Share Posted May 8, 2007 The one that you use (in my opinion) is the best way, however the last .""; is not needed (of course keep the semicolon). Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248324 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 honestly... its really down to personal preference... personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?> What does it do? <?php <?=$var?> ?> Nothing anymore it has been depreciated. Best practice is to use this: <html> <title><?php print $var; ?></title> Essentially what it used to do was just print a variable to the string, but some issues arose with that so they made that functionality depreciated as of 4.4 I believe not sure. Anyhow if you plan on upgrading php anytime soon that will break anyscripts that use that methodology. Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248327 Share on other sites More sharing options...
Trium918 Posted May 8, 2007 Share Posted May 8, 2007 honestly... its really down to personal preference... personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?> What does it do? <?php <?=$var?> ?> Nothing anymore it has been depreciated. Best practice is to use this: <html> <title><?php print $var; ?></title> Essentially what it used to do was just print a variable to the string, but some issues arose with that so they made that functionality depreciated as of 4.4 I believe not sure. Anyhow if you plan on upgrading php anytime soon that will break anyscripts that use that methodology. What type of issues arosed? Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248369 Share on other sites More sharing options...
per1os Posted May 8, 2007 Share Posted May 8, 2007 The php developers decided it was not a good idea or maybe they wanted to keep PHP more uniform, unsure. Either way it has been depreciated in newer versions of PHP. Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248372 Share on other sites More sharing options...
taith Posted May 9, 2007 Share Posted May 9, 2007 i've ran php 4.x, 5, 5.2, and have yet to find one where <?=$var?> doesnt work... besides... most of other php upgrades have been backwards compatable... i dont see why they'd cut this... maybe its not cool enough... lol Quote Link to comment https://forums.phpfreaks.com/topic/50536-a-simple-php-echo-question/#findComment-248857 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.