Forum Moderators: coopster

Message Too Old, No Replies

Insert new line in source code, not on page

         

radiator251

5:25 am on Dec 17, 2009 (gmt 0)

10+ Year Member



I have a bunch of while and for loops that create select menus and radio buttons based on database content. Everything works fine, but it would be great for further debugging purposes if I could view the source code and the PHP output would be on different lines (as if I wrote it all in html) instead of all on the same line. I can put in <br /> or \n after each <option> for the select menus, but I cannot do the same for the radio buttons because my page format requires that they all be on the same line. Is there another way of doing this?

Here's the code; I want the source code to have a break after each radio button. $i comes from the for loop that runs this code (it runs several times, so I made it a for loop to avoid repetitive code).


$selected = " checked='checked'";
if($sunday == $i){$sun_selected = $selected;}
if($monday == $i){$mon_selected = $selected;}
if($tuesday == $i){$tue_selected = $selected;}
if($wednesday == $i){$wed_selected = $selected;}
if($thursday == $i){$thu_selected = $selected;}
if($friday == $i){$fri_selected = $selected;}
if($sat== $i){$sat_selected = $selected;}
echo "<label>Sun</label><input type='radio' name='sun' value='$i'$sun_selected/> ";
echo "<label>Mon</label><input type='radio' name='mon' value='$i'$mon_selected/> ";
echo "<label>Tue</label><input type='radio' name='tue' value='$i'$tue_selected/> ";
echo "<label>Wed</label><input type='radio' name='wed' value='$i'$wed_selected/> ";
echo "<label>Thu</label><input type='radio' name='thu' value='$i'$thu_selected/> ";
echo "<label>Fri</label><input type='radio' name='fri' value='$i'$fri_selected/> ";
echo "<label>Sat</label><input type='radio' name='sat' value='$i'$sat_selected/> ";

Thanks!

ALKateb

12:23 pm on Dec 17, 2009 (gmt 0)

10+ Year Member



if it's only for debugging purpose you can output whatever you want as an html comment

echo "<!-- whatever you want here! -->";

TheMadScientist

12:50 pm on Dec 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think this is what you're looking for:

echo "<label>Sun</label><input type='radio' name='sun' value='$i'$sun_selected/> \n";
echo "<label>Mon</label><input type='radio' name='mon' value='$i'$mon_selected/> \n";

You are already, but make sure you use double quotes not single quotes for your string in this case or they won't be expanded and create new lines...

TheMadScientist

12:52 am on Dec 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I guess I didn't read your question very well, and now I really don't understand it, because putting a \n (new line) in the HTML source code should have no effect on the display unless you are using <pre> tags.

You should really be able to put \n\n\n\n\n\n\n and have the radio buttons display on the same line in the browser even though there is huge white-space in the HTML source code.

If you are still having issues, please explain a bit more...