satre Posted March 17, 2010 Share Posted March 17, 2010 Hi, I need to have php generate some HTML code for me that needs to be formatted nicely so it can be read easily. Right now, it's just printing every statement without any line breaks so it's just all one big paragraph. The HTML works and looks fine in a browser, it's just hard to read the source code when you want to view the source code. Here's a sample of the relevant php: echo "<!-- BE SURE TO SELECT TAGS: "; if(isset($_POST['Tag_Tesla'])) { $Tag_Tesla = $_POST['Tag_Tesla']; } else { $Tag_Tesla = array(); } $i = 0; //first index while ($i < count($Tag_Tesla)) { echo "Magnet Strength = $Tag_Tesla[$i]"; ++$i; } if(isset($_POST['Tag_Op_System'])) { $Tag_Op_System = $_POST['Tag_Op_System']; } else { $Tag_Op_System = array(); } $i = 0; //first index while ($i < count($Tag_Op_System)) { echo "Operating System = $Tag_Op_System[$i]"; ++$i; } if(isset($_POST['Tag_Age_Class'])) { $Tag_Age_Class = $_POST['Tag_Age_Class']; } else { $Tag_Age_Class = array(); } $i = 0; //first index while ($i < count($Tag_Age_Class)) { echo "Age class = $Tag_Age_Class[$i]"; ++$i; } echo "-->"; echo "<br>"; echo "<!-- BE SURE TO SELECT CATEGORIES: "; if(isset($_POST['Category_MSK'])) { $Category_MSK = $_POST['Category_MSK']; } else { $Category_MSK = array(); } $i = 0; //first index while ($i < count($Category_MSK)) { echo "MSK = $Category_MSK[$i]"; ++$i; } echo "-->"; And here's the format of the HTML source code it gives me (note that it's all squashed together): <!-- BE SURE TO SELECT TAGS: Magnet Strength = 1.5Operating System = 15Age class = Adult--><br><!-- BE SURE TO SELECT CATEGORIES: MSK = shoulder--> I would like it to look like this: <!-- BE SURE TO SELECT TAGS: Magnet Strength = 1.5 Operating System = 15 Age class = Adult--> <!-- BE SURE TO SELECT CATEGORIES: MSK = shoulder--> Any ideas how to do this? Thanks! Satre Quote Link to comment https://forums.phpfreaks.com/topic/195566-nicely-formatting-html-source-code-generated-with-php/ Share on other sites More sharing options...
Wolphie Posted March 17, 2010 Share Posted March 17, 2010 You should be using "\n" to generate a new line. echo "<!-- BE SURE TO SELECT TAGS: \n"; if(isset($_POST['Tag_Tesla'])) { $Tag_Tesla = $_POST['Tag_Tesla']; } else { $Tag_Tesla = array(); } $i = 0; //first index while ($i < count($Tag_Tesla)) { echo "Magnet Strength = $Tag_Tesla[$i]\n"; ++$i; } if(isset($_POST['Tag_Op_System'])) { $Tag_Op_System = $_POST['Tag_Op_System']; } else { $Tag_Op_System = array(); } $i = 0; //first index while ($i < count($Tag_Op_System)) { echo "Operating System = $Tag_Op_System[$i]\n"; ++$i; } if(isset($_POST['Tag_Age_Class'])) { $Tag_Age_Class = $_POST['Tag_Age_Class']; } else { $Tag_Age_Class = array(); } $i = 0; //first index while ($i < count($Tag_Age_Class)) { echo "Age class = $Tag_Age_Class[$i]\n"; ++$i; } echo "-->\n"; echo "<br>\n"; echo "<!-- BE SURE TO SELECT CATEGORIES: \n"; if(isset($_POST['Category_MSK'])) { $Category_MSK = $_POST['Category_MSK']; } else { $Category_MSK = array(); } $i = 0; //first index while ($i < count($Category_MSK)) { echo "MSK = $Category_MSK[$i]\n"; ++$i; } echo "-->\n"; Quote Link to comment https://forums.phpfreaks.com/topic/195566-nicely-formatting-html-source-code-generated-with-php/#findComment-1027614 Share on other sites More sharing options...
satre Posted March 17, 2010 Author Share Posted March 17, 2010 Yes! That works! Thank you so much! Best, Satre Quote Link to comment https://forums.phpfreaks.com/topic/195566-nicely-formatting-html-source-code-generated-with-php/#findComment-1027618 Share on other sites More sharing options...
PFMaBiSmAd Posted March 17, 2010 Share Posted March 17, 2010 You can also use \t to tab/indent the lines in the 'view source' Quote Link to comment https://forums.phpfreaks.com/topic/195566-nicely-formatting-html-source-code-generated-with-php/#findComment-1027624 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.