kristen Posted April 8, 2008 Share Posted April 8, 2008 <?php echo $row['id']; ?> OR <? echo $row['id']; ?> OR <?=$row['id']; ?> Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/ Share on other sites More sharing options...
trq Posted April 8, 2008 Share Posted April 8, 2008 The first is the only one guaranteed to be supported. Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-511710 Share on other sites More sharing options...
bubblebla Posted April 8, 2008 Share Posted April 8, 2008 since there is a topic about echo... i wanna ask... how to call all data from table <? echo ......<what should i put here>.......; ?> Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-511714 Share on other sites More sharing options...
kevin7 Posted April 8, 2008 Share Posted April 8, 2008 kristen: it depends on you, 3 of them will work, but the third once can save you some times. for my own preference, i use the second one. bubblebla: call data from table? i assume you mean from database's table.. not sure if my explanation is correct, normally, when u make a query, you will have something like.. $row = mysql_fetch_array($query); if you don't know the column name, you can echo the data like $row[0], $row[1].... if you know the column name, you can echo the data like $row['id'], $row['name']... if you use extract($row), you can straight away use it according to the column name, $id, $name... cheers... Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-511716 Share on other sites More sharing options...
bubblebla Posted April 8, 2008 Share Posted April 8, 2008 hi kevin.. yes.. table i mentioned is from the database.. thank you for your explanation. Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-511757 Share on other sites More sharing options...
kristen Posted April 8, 2008 Author Share Posted April 8, 2008 Thanks, I've always been curious about this. I've seen it all three ways, but I normally use the 2nd. Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-511997 Share on other sites More sharing options...
GingerRobot Posted April 8, 2008 Share Posted April 8, 2008 Both the second and third options rely on the short_open_tag setting being turned on in your php.ini I prefer the first - a couple extra characters is worth the fact that it will definitely work. It's also worth the fact that we get syntax highlighting on the forum with those tags. Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-512008 Share on other sites More sharing options...
discomatt Posted April 8, 2008 Share Posted April 8, 2008 I will second GingerRobot and thorpe. The only time you should use the second or third option is if the script is designed for one server, and you know it will always have short_open_tag on. If, for any reason, it gets turn off, anything using <? or <?= to begin parsing PHP will NOT be parsed. This can reveal sensitive variable information, vulnerabilities in your code, or simply allow someone to copy your source. In my opinion, the guarantee that PHP will parse is worth the few extra characters. Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-512055 Share on other sites More sharing options...
haku Posted April 8, 2008 Share Posted April 8, 2008 I'll 3rd that. The second and third methods aren't reliable unless you personally manage the server that the script lies on. Link to comment https://forums.phpfreaks.com/topic/100076-what-is-the-best-way-to-echo/#findComment-512158 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.