Getting PHP generated HTML to display properly.
Moderator: General Moderators
Getting PHP generated HTML to display properly.
When I use PHP to display HTML, it always shows up on a single line when I view page source.
It makes it much more difficult to debug as well as making it look unprofessional.
How can I get it to display on different lines?
It makes it much more difficult to debug as well as making it look unprofessional.
How can I get it to display on different lines?
Re: Getting PHP generated HTML to display properly.
You need to add all the standard HTML formatting tags, <p>, <br />, etc.
Re: Getting PHP generated HTML to display properly.
This sounds weird. Post a snippet of code you are having trouble with. Also, when you view the page source from the browser, the php code will not show up, only the html the php is created will show up.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: Getting PHP generated HTML to display properly.
Pazuzu156 wrote:This sounds weird. Post a snippet of code you are having trouble with. Also, when you view the page source from the browser, the php code will not show up, only the html the php is created will show up.
This is a snippet:
Code: Select all
<div id="text_body">
<div id="left_menu"><p><a href="album.php" onclick="window.open('album.php?action=add&album_id=','Add','width=410,height=480')">Add Album</a></p></div><div id="main"><table><tr><td><strong>Album Name</strong></td><td><strong>Description</strong></td><td><strong>Date Created / Last Update</strong></td><td></td></tr></table></div><div id="clear"></div> </div>
<div id="text_bottom">
<div id="text_bottom_left"></div>
<div id="text_bottom_right"></div>
</div>
In View Page Source it is all on one line
Code: Select all
<div id="text_body">
<div id="left_menu"><p><a href="album.php" onclick="window.open('album.php?action=add&album_id=','Add','width=410,height=480')">Add Album</a></p></div><div id="main"><table><tr><td><strong>Album Name</strong></td><td><strong>Description</strong></td><td><strong>Date Created / Last Update</strong></td><td></td></tr></table></div><div id="clear"></div> </div>
It is displayed on separate lines
Code: Select all
<div id="text_bottom">
<div id="text_bottom_left"></div>
<div id="text_bottom_right"></div>
</div>
Re: Getting PHP generated HTML to display properly.
Okay, I understand what you're getting at. As I see it, when you go to debug, the page source from the browser isn't the best idea. What text editor are you using? And what operating system?
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: Getting PHP generated HTML to display properly.
Dreamweaver CS5Pazuzu156 wrote:Okay, I understand what you're getting at. As I see it, when you go to debug, the page source from the browser isn't the best idea. What text editor are you using? And what operating system?
Windows 7
Re: Getting PHP generated HTML to display properly.
Ok, Dreamweaver is good for web design, I cannot say it's good for php as sometimes php wont even show up on the pages. Use notepad++, its a free open source code editor for all types of coding needs. It has line numbers and is excellent for hand coding. Also, Eclipse has a program just for php and if I'm correct will parse your code as well. Check them out.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: Getting PHP generated HTML to display properly.
I've tried notepad++ but I like how dreamweaver manages sites.Pazuzu156 wrote:Ok, Dreamweaver is good for web design, I cannot say it's good for php as sometimes php wont even show up on the pages. Use notepad++, its a free open source code editor for all types of coding needs. It has line numbers and is excellent for hand coding. Also, Eclipse has a program just for php and if I'm correct will parse your code as well. Check them out.
But I'll try to get into Notepad++ and check out Eclipse.
Another fear I have is that if someone, looks at my code, it will look sloppy and unprofessional.
Re: Getting PHP generated HTML to display properly.
That is a possibility, If you look at most professional websites, alot of the codes can look that way.
With my code, i used a mix, have a look:
And I ended up with this as the source, aligned in good order.
With my code, i used a mix, have a look:
Code: Select all
<html>
<body>
<?php
function spamcheck($field)
{
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
} else {
return FALSE;
}
}
if (isset($_REQUEST['email']))
{
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE)
{
echo "Invalid input";
} else {
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail("kklein_webmaster@jae-entertainment.we.bs", "Subject: $subject",
$message, "From: $email" );
echo "Thank you for using our mail form";
}
} else {
echo "<form method='post' action='email.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>
Code: Select all
<html>
<body>
<form method='post' action='email.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>
</body>
</html>
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: Getting PHP generated HTML to display properly.
I figured it out.
I was putting each line of HTML in seperate echo() statements.
But when I out it all in one, it worked.
Thanks Pazuzu156 for the help and tips on the text editors.
I was putting each line of HTML in seperate echo() statements.
But when I out it all in one, it worked.
Thanks Pazuzu156 for the help and tips on the text editors.
Re: Getting PHP generated HTML to display properly.
No problem at all, when you post them into separate echo() commands, the computer reads it without the professional look. So it will parse the codes and show in a single line. Also, alot is shown in multiple echo() codes so depending on what you have echo in will determine whether it shows in one line or multiple.
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Re: Getting PHP generated HTML to display properly.
I have a solution to your issue. When you post things into separate echos, if you want a more professional look, at the end of the echo, make a new line. When you make a new line, you use \n. it would look like so:
In the browser, your page will look like this:
The page source will look like this:
Hope this helps.
Code: Select all
<?php
echo "Hello\n";
echo "World!\n";
echo "Such a lovely day huh?";
?>
Code: Select all
Hello World!
Such a lovely day huh?
Code: Select all
<html>
<body>
Hello
World!<br />
Such a lovely day huh?
</body>
</html>
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156