Solved

Preventing PHP Tidy from removing an empty tag?

Posted on 2004-10-08
7
514 Views
Last Modified: 2008-02-07
I'm using PHP Tidy to clean up my HTML before it's sent to the browser.

We have a requirement to have a drop-down box with a blank (space) option, Yes, and No.

The html looks like this:

<select name="fieldname1" class="input">
<option value="" class="input" selected="true"></option>
<option value="Y" class="input">Yes</option>
<option value="N" class="input">No</option>
</select>

After Tidy gets ahold of this it changes it to:

<select name="fieldname1" class="input"><option value="N" class="input">
                                          No
</option><option value="Y" class="input">
                                          Yes
</option></select>

Does anyone have any idea as to how I can prevent Tidy from removing the empty <option> tag?

Thanks in advance,

Ian

0
Comment
Question by:ianwpugh
  • 3
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 500 total points
ID: 12258646
don't leave it blank, use the non-breaking space instead ( &nbsp; )


<select name="fieldname1" class="input">
<option value="" class="input" selected="true">&nbsp;</option>
<option value="Y" class="input">Yes</option>
<option value="N" class="input">No</option>

This will give you what you want
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12258679
is PHP Tidy a program?
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 12258749
TIDY is a HTML source compressor/formatter put out by the W3C.  
It's written in C and can be found online as "HTML Tidy".  
It's currently hosted on sourceforge at http://tidy.sourceforge.net/

It can take an ugly block of HTML code and turn it into something nicely formatted.

See http://www.w3.org/People/Raggett/tidy/ for some examples
See http://cgi.w3.org/cgi-bin/tidy to use the CGI version on any publicly accessable URL
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 12

Expert Comment

by:minichicken
ID: 12258864
Good stuff, thanks petoskey-001, will go have a look now and download it and ofcoz use it.... Thanks again :)
0
 
LVL 7

Expert Comment

by:petoskey-001
ID: 12259756
NP.  
BTW offtopic but I noticed you have your first 10,000.  For more fun also track you rank and percentage.
For instance in Member Rank (view rank link) it shows your 4408 of 60428 experts so your at 92% of people who have more then 0 points.  It's surprising how fast you climb and just how far apart the real top people are.
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12259979
Yeah, thanks for the info, I am pretty much new to this EE thing, still finding my way round the place..... surprising ranking results... :)
0
 

Author Comment

by:ianwpugh
ID: 12286459
Thanks for the advice.

After looking through the XML that's used to generate the HTML, I found the error was actually in the HTML parser, not Tidy.. Heh.. Thanks anyway :)
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question