Jump to content

nicely formatting HTML source code generated with php?


satre

Recommended Posts

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

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.