473,748 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Indent HTML portions question

Given the following piece of code, I was looking for suggestions on how to beautify
the portion of the HTML where I jump out of php mode and back in again. The HTML does
not have any indenting in order to make the output more readable. However, by not
indenting the php code, the php code becomes slightly more difficult to read. Is there
a way to have both the php and HTML codes indent correctly?

Thanks.

<?php
} else {

// Connect to the database.
$dbConnection = dbConnect($dbHo st, $dbUser, $dbPassword, $db);

// Check required fields.
if ($_POST['newid'] == '' or $_POST['newname'] == '' or $_POST['newemail'] == '') {
errorMessage("O ne or more required fields were left blank. Please fill them in and try again.");
}

$query = "SELECT COUNT(*) FROM user WHERE userid = '$_POST[newid]'";
$result = mysql_query($qu ery);
if (!$result) {
errorMessage("A database error occurred.");
}

// Check to see if the userid already exists.
if (mysql_result($ result, 0, 0) > 0) {
errorMessage("A user with the user id you requested already exists.");
}

$newpassword = "test";

$query = "INSERT INTO user SET
userid = '$_POST[newid]',
password = PASSWORD('$newp assword'),
fullname = '$_POST[newname]',
email = '$_POST[newemail]',
notes = '$_POST[newnotes]'";

if (!mysql_query($ query)) {
errorMessage("$ query");
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>Registra tion SUCCESS!</TITLE>
</head>
<body>
Database insertion was successful. You are now registered.
</body>
</html>
<?php
}
?>
Jul 17 '05 #1
2 2328
In article <RO************ ****@newssvr15. news.prodigy.co m>, Squirrel wrote:
Given the following piece of code, I was looking for suggestions on how to beautify
the portion of the HTML where I jump out of php mode and back in again. The HTML does
not have any indenting in order to make the output more readable. However, by not
indenting the php code, the php code becomes slightly more difficult to read. Is there
a way to have both the php and HTML codes indent correctly?


The lazy solution would be to buffer the output.
Let tidy clean up the buffer.
And finally output the clean HTML.

--
Tim Van Wassenhove <http://home.mysth.be/~timvw>
Jul 17 '05 #2
"Squirrel" <no@spam.com> wrote in message
news:RO******** ********@newssv r15.news.prodig y.com...
Given the following piece of code, I was looking for suggestions on how to beautify the portion of the HTML where I jump out of php mode and back in again. The HTML does not have any indenting in order to make the output more readable. However, by not indenting the php code, the php code becomes slightly more difficult to read. Is there a way to have both the php and HTML codes indent correctly?


One answer is to run it through a PHP formatter,
such as ours (See
http://www.semanticdesigns.com/Produ...Formatter.html)
Our formatter will reformat the HTML as well as the PHP source code.
See result below.

I had to add an IF () { fragment head to make your source code legal.
Your $query variable now looks a little funny, because of disagreement
on how to prettyprint very long string constants. We print them
with embedded newlines escaped as "\n". If you want that to
be more readable, you could use the concatenation operator "."
at the end of each line of the string constant, and the prettyprinter
would then line up the string constants nicely.
That version is listed a little further down.

The nice thing about prettyprinting is that you can hack at your
source whatever way is convenient, and let the prettyprinter
clean it all up.

--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com

-- First version ---

<?php
if (dummy)
{
}
else
{
// Connect to the database.
$dbConnection=d bConnect($dbHos t,$dbUser,$dbPa ssword,$db);
// Check required fields.
if ($_POST['newid'] == '' or $_POST['newname'] == '' or
$_POST['newemail'] == '')
{
errorMessage("O ne or more required fields were left blank.
Please fill them in and try again.");
}
$query="SELECT COUNT(*) FROM user WHERE userid = '$_POST[newid] '";
$result=mysql_q uery($query);
if (!$result)
{
errorMessage("A database error occurred.");
}
// Check to see if the userid already exists.
if (mysql_result($ result,0,0)>0)
{
errorMessage("A user with the user id you requested already
exists.");
}
$newpassword="t est";
$query="INSERT INTO user SET\n userid =
'$_POST[newid] ',\n password = PASSWOR
D('$newpassword '),\n fullname = '$_POST[newname] ',\n
email = '$_POST[newemail] ',\n
notes = '$_POST[newnotes] '";
if (!mysql_query($ query))
{
errorMessage("$ query");
}
?>
<!doctype
htmlpublic"-//w3c//dtdhtml4.01tran sitional//en""http://www.w3.org/tr/html4/l
oose.dtd">
<html>
<head>
<title>Registra tion SUCCESS!</title>
</head>
<body> Database insertion was successful. You are now registered.
</body>
</html>
<?php
}
?>
-- Second version --

<?php
if (dummy)
{
}
else
{
// Connect to the database.
$dbConnection=d bConnect($dbHos t,$dbUser,$dbPa ssword,$db);
// Check required fields.
if ($_POST['newid'] == '' or $_POST['newname'] == '' or
$_POST['newemail'] == '')
{
errorMessage("O ne or more required fields were left blank.
Please fill them in and try again.");
}
$query="SELECT COUNT(*) FROM user WHERE userid = '$_POST[newid] '";
$result=mysql_q uery($query);
if (!$result)
{
errorMessage("A database error occurred.");
}
// Check to see if the userid already exists.
if (mysql_result($ result,0,0)>0)
{
errorMessage("A user with the user id you requested already
exists.");
}
$newpassword="t est";
$query="INSERT INTO user SET"
. "userid = '$_POST[newid] ',"
. "password = PASSWORD('$newp assword'),"
. "fullname = '$_POST[newname] ',"
. "email = '$_POST[newemail] ',"
. ".notes = '$_POST[newnotes] '";
if (!mysql_query($ query))
{
errorMessage("$ query");
}
?>
<!doctype
htmlpublic"-//w3c//dtdhtml4.01tran sitional//en""http://www.w3.org/tr/html4/l
oose.dtd">
<html>
<head>
<title>Registra tion SUCCESS!</title>
</head>
<body> Database insertion was successful. You are now registered.
</body>
</html>
<?php
}
?>
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4141
by: John Wellesz | last post by:
If you are coding php using GVIM, you will appreciate this new indent script: Download there: http://www.vim.org/scripts/download_script.php?src_id=3710 or here: http://www.2072productions.com/vim/indent/php.vim
1
3044
by: hongping | last post by:
I am having problems transforming a xml doc into html with proper indenting. Here is the xslt <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xslt" xmlns="http://www.w3.org/1999/xhtml">
21
10942
by: Wladimir Borsov | last post by:
Assume I want to publish a longer article on a web page. One of the paragraphs I want to display with an indent. Read: All text lines of this paragraph should be displayed with (let's say 8) blanks from the "normal" left side. How do I do that without coding "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ? Is there something like <TAB size=8> ..... </TAB> ?
22
27251
by: Firas | last post by:
Hi, Is there a CSSish way to indent a paragraph except for the first line? I tried p:first-line { text-indent: 0em; }
2
1724
by: cawoodm | last post by:
I have a simple xml file: <document> <header> <title>Hello World!</title> </header> </document> Which I want to transform into HTML. The following transform produces indented XHTML:
0
1287
by: saabi | last post by:
How to indent length 4 a tab in IE? The text in this CDATA was some html code, it would indent length 8 a tab in IE, but I like to indent length 4 like in the original html editor, How to change the xsl code? ----------------------------------------------------------- Indent4ATab.xml <?xml version="1.0" encoding="GB2312"?> <?xml-stylesheet type="text/xsl" href="Indent4ATab.xsl"?> <htmlCode><!]></htmlCode>
4
1722
by: dt | last post by:
Greetings, I'm having some trouble understanding the plethora of options available for GNU indent for my C code. Except for the function's opening {, I want all code to line up under the opening { of the block it resides in. Let me explain with an example. I'm using this command,
21
7643
by: Bogdan | last post by:
Can anyone recommend a program for indentation of C preprocessor directives. My file looks like this: #ifdef a #define b #else #define c #endif int main() {
1
3061
by: humtum | last post by:
Greetings Everyone! I am working on a Java application where I have to develop a Swings client which talks to a web-server. The client sends the HTTP get request for a specific resource which it receives as HTML and uses JEditorPane to render the HTML. The overall architecture is like I have a HTML request processor thread which connects to a particular URL and GETs the resource. The resource is a "String" which contains the HTML. Now is...
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.