C4talyst Posted October 1, 2007 Share Posted October 1, 2007 Hey there again freaks! Say I want to echo a really large block of html. How do I do this without the least amount of php code, meaning I dont want to echo ""; every line. Can I just echo the whole large chunk of html somehow? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/ Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 You can do it this way: <?php print<<<HERE All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. All your HTML/text goes here. HERE; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359333 Share on other sites More sharing options...
BlueSkyIS Posted October 1, 2007 Share Posted October 1, 2007 another alternative is to leave PHP and place plain HTML in between tags: <?php // Some PHP code here... ?> <HTML> <BODY> just plain HTML in here <?php // more PHP code in here... ?> Back to plain HTML </BODY> </HTML> Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359335 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 Thanks guys...obviously I'm a huge noob. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359349 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 Don't forget to solve the topic Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359351 Share on other sites More sharing options...
weemikey Posted October 1, 2007 Share Posted October 1, 2007 I build HTML in a big variable and then echo the variable at the end. I don't know what's "right" in programming, I just try to make it work. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359392 Share on other sites More sharing options...
LemonInflux Posted October 1, 2007 Share Posted October 1, 2007 Another alternative would be to write the bit you want echo'ing, save it as a .txt somewhere, and call it from there. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359397 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 Ahh, thanks so much for all this information guys. I think I may need some more help with this though. Basically I took some code I found in a tutorial online for password protecting some of my content. The password code has an echo line where the original author states to insert your content. Well, my content contains additional php coding and that's causing some problems. This is the page in question: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>ACDC Membership Database</title> <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us"> <meta name="Robots" content="index,follow"> <style type="text/css">@import "style.css";</style> </head> <body> <?php include("config.php"); $cookuser = $_COOKIE["cookuser"]; $cookpass = $_COOKIE["cookpass"]; $adminpass = md5($adminpass); if($cookuser && $cookpass) { if(($cookuser == $adminuser) && ($cookpass == $adminpass)){ echo("You have successfully logged in!"); //Paste protected content here: echo "<div id=\"mdb_top\">"; echo "<div id=\"mdb_nav\" style=\"padding: 2px;\" align=\"center\"><a href=\"index.php\">MDB Home</a> | <a href=\"add.php\">Add Nation</a> | <a href=\"search.php\">Find Nation</a></div>"; echo "</div>"; echo " <table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" width=\"700\">"; echo " <tr>"; echo " <td width=\"700\" colspan=\"6\" bgcolor=\"#414B3F\">"; echo " <h3>ACDC Membership Database</h3>"; echo " </td>"; echo " </tr>"; echo " <tr>"; echo " <td width=\"100\" bgcolor=\"#768872\" valign=\"top\" align=\"left\">"; echo " <b>ID</b>"; echo " </td>"; echo " <td width=\"130\" bgcolor=\"#768872\" valign=\"top\" align=\"left\">"; echo " <b>Nation</b>"; echo " </td>"; echo " <td width=\"130\" bgcolor=\"#768872\" valign=\"top\" align=\"left\">"; echo " <b>Ruler</b>"; echo " </td>"; echo " <td width=\"120\" bgcolor=\"#768872\" valign=\"top\" align=\"left\">"; echo " <b>ACDC User</b>"; echo " </td>"; echo " <td width=\"120\" bgcolor=\"#768872\" valign=\"top\" align=\"left\">"; echo " <b>Position</b>"; echo " </td>"; echo " <td width=\"100\" bgcolor=\"#768872\" valign=\"top\" align=\"left\">"; echo " <b>Commands</b>"; echo " </td>"; echo " </tr>"; <? //connect to mysql //change user and password to your mySQL name and password mysql_connect("localhost","username","password"); //select which database you want to edit mysql_select_db("database"); //select the table $result = mysql_query("select * from members limit 30"); //grab all the content while($r=mysql_fetch_array($result)) { $id=$r["id"]; $cnnation=$r["cnnation"]; $cnruler=$r["cnruler"]; $acdcuser=$r["acdcuser"]; $positions=$r["positions"]; $nationlink=$r["nationlink"]; //display the row echo "<tr>"; echo "<td width=\"100\" bgcolor=\"#9DAB9B\" valign=\"top\" align=\"left\">"; echo "$id"; echo "</td>"; echo "<td width=\"130\" bgcolor=\"#9DAB9B\" valign=\"top\" align=\"left\">"; echo "<a href=\"$nationlink\" target=\"_blank\">$cnnation</a>"; echo "</td>"; echo "<td width=\"130\" bgcolor=\"#9DAB9B\" valign=\"top\" align=\"left\">"; echo "$cnruler"; echo "</td>"; echo "<td width=\"120\" bgcolor=\"#9DAB9B\" valign=\"top\" align=\"left\">"; echo "$acdcuser"; echo "</td>"; echo "<td width=\"120\" bgcolor=\"#9DAB9B\" valign=\"top\" align=\"left\">"; echo "$positions"; echo "</td>"; echo "<td width=\"100\" bgcolor=\"#9DAB9B\" valign=\"top\" align=\"left\">"; echo "<a href='edit.php?cmd=edit&id=$id'>Edit</a> | <a href='delete.php?cmd=delete&id=$id'>Delete</a>"; echo "</td>"; echo "</tr>"; } ?> echo " </table>"; } else{ echo($incorrect_error_message); } } else{ echo($not_logged_in_message_error_message); } ?> </body> The <? line just before //connect to mysql is the one kicking out an error. I know I should really get some books and php and dig into them, but I kinda need to get this done soon. This is my intro to php/mysql. Thanks so much for all the help. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359570 Share on other sites More sharing options...
trq Posted October 1, 2007 Share Posted October 1, 2007 Remove the <? Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359580 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 Really? Should I remove the ?> that closes it as well? Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359598 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 Really? Should I remove the ?> that closes it as well? Yes, because you have PHP below it...so it won't be executed. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359601 Share on other sites More sharing options...
MmmVomit Posted October 1, 2007 Share Posted October 1, 2007 You need to make sure any echo statement is between PHP tags. <?php echo 'foo'; echo 'bar'; ?> You've currently got opening and closing PHP tags all over the place with no rhyme or reason. Here are two different approaches. <?php // code // code // code $var = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. "; echo $var; // more code ?> OR <?php // code // code // code ?> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. <?php // more code ?> I prefer the second approach. Do you see how I exited PHP mode and simply wrote out everything instead of using the echo command? Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359604 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 Thank you guys so much! Vomit, I'm using this code to enable a passwd protected page: <?php include("config.php"); $cookuser = $_COOKIE["cookuser"]; $cookpass = $_COOKIE["cookpass"]; $adminpass = md5($adminpass); if($cookuser && $cookpass) { if(($cookuser == $adminuser) && ($cookpass == $adminpass)){ echo("You have successfully logged in!"); } else{ echo($incorrect_error_message); } } else{ echo($not_logged_in_message_error_message); } ?> See this line: echo("You have successfully logged in!"); I need to replace that with about 100 lines of html that also includes more php code. So I can't figure out how to get around that and use your suggestion. It seems like I _have_ to embed more php code in there. I'm terribly sorry for my ignorance on this, I'm probably making some of you dumber for having read this. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359608 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 I'm starting to understand...slowly. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359611 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 If you need to print a large chunk of HTML that has bits of PHP in it, use the example I gave you in my first post. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359618 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 Got it working using your second approach Vomit, thanks so much. Just took me awhile to figure out how to open and close the php throughout the page. This forum is really great, thanks all of you. I'll be sure to mark my topics resolved. Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359626 Share on other sites More sharing options...
C4talyst Posted October 1, 2007 Author Share Posted October 1, 2007 If you need to print a large chunk of HTML that has bits of PHP in it, use the example I gave you in my first post. Hey poco, I tried that but I kept getting a T_ENCAPSED_AND_WHITESPACE error, even after I removed all the blank spaces. Your method is greatly appreciated though and I will likely refer to this thread again later. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359629 Share on other sites More sharing options...
pocobueno1388 Posted October 1, 2007 Share Posted October 1, 2007 It's probably because you don't have the last line at the very left of your text editor. <?php print<<<HERE blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah HERE; //<---This line has to be all the way to the left ?> Quote Link to comment https://forums.phpfreaks.com/topic/71397-solved-really-easy-question-php-echo/#findComment-359631 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.