Forum Moderators: coopster

Message Too Old, No Replies

displayinging HTML DTD

PHP and Quotation Marks

         

Oaf357

7:11 pm on Mar 7, 2003 (gmt 0)

10+ Year Member


I'm trying to write a script to generate an HTML 4.01 compliant page. The problem I'm having is with HTML DTD insertion. I'd like to create includes in the main script to point to the individual DTDs and then when the form is submitted the correct DTD is displayed based on user input. DTDs use quotation marks and this is where my problem begins.

Using your typical HTML " doesn't work because it throws in backslashes for some reason. I'm trying to create the include to echo the right characters as needed but am having some difficulties. Please take a look at the include and maybe you can see what I'm doing wrong. Thanks in advance for any help.

<?php

echo '!DOCTYPE HTML PUBLIC'; echo '&quot;'; echo'-//W3C//DTD HTML 4.01//EN'; echo '&quot';\n
echo 'http://www.w3.org/TR/html4/strict.dtd'; echo '&quot;';

?>

xmarklar

7:46 pm on Mar 7, 2003 (gmt 0)

10+ Year Member



so i guess just putting backslashes before your quotes, like you would normally do, doesn't work?

Oaf357

8:13 pm on Mar 7, 2003 (gmt 0)

10+ Year Member



Backslashes before the quote?

rfontaine

8:48 pm on Mar 7, 2003 (gmt 0)

10+ Year Member



Hey Oaf,

Try this:

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">';

Oaf357

9:09 pm on Mar 7, 2003 (gmt 0)

10+ Year Member



That echo statement won't work due to the fact that I need the code actually displayed on the page. That was my original idea but it dawned on me that it would be hidden from "humans".

[edited by: Oaf357 at 9:13 pm (utc) on Mar. 7, 2003]

Birdman

9:12 pm on Mar 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or just the opposite:

echo "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/ strict.dtd'>";

Also see the PHP [php.net] manual and read about addslashes() [php.net], stripslashes() [php.net], htmlspecialchars() [php.net] and quotemeta() [php.net].

Have fun ;)

Oaf357

9:26 pm on Mar 7, 2003 (gmt 0)

10+ Year Member


That doesn't work either because the statement being echoed has to been seen on the page.

jatar_k

9:29 pm on Mar 7, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I guess you are trying to have that code visible and not interpreted by the browser?

If so why not put it in a textarea so people can see it, otherwise the browser will interpret it and never show it.

dingman

9:31 pm on Mar 7, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need the code actually displayed on the page.

so...

echo htmlentities('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">');

better?

Oaf357

9:31 pm on Mar 7, 2003 (gmt 0)

10+ Year Member


Basically I want this:
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN' 'http://www.w3.org/TR/html4/ strict.dtd'>

Displayed by a PHP include. A textarea won't work in this scenario.

rfontaine

9:39 pm on Mar 7, 2003 (gmt 0)

10+ Year Member



Well then if you just want it displayed on the web page for all to see, do this:

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

(do not include the above within the php tags and it will display on the page fine and dandy)

aspr1n

11:10 pm on Mar 7, 2003 (gmt 0)

10+ Year Member



maybe it's cos I'm a C man at heart, but I'd just keep it simple:


printf( '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">');

asp

Oaf357

11:33 pm on Mar 7, 2003 (gmt 0)

10+ Year Member


Okay. I need PHP includes. The output is going to be based on a users selection. If I wanted it to be statically displayed that's easy. When a user specifies that they want a strict DTD (via a pulldown menu) the script will call on strict.inc and output the appropriate, human readable text.

If an include isn't the right way to go about this (I'm pretty sure it is) then please tell me.

Oaf357

11:46 pm on Mar 7, 2003 (gmt 0)

10+ Year Member


htmlentities isn't working for some reason either. I'm going to tinker with that and see what the deal is.

Oaf357

11:55 pm on Mar 7, 2003 (gmt 0)

10+ Year Member


htmlentities won't work.

I need to be able to spit out HTML as text.

Oaf357

12:05 am on Mar 8, 2003 (gmt 0)

10+ Year Member



printf does not work either. I'm starting to doubt whether or not an include is the right method but no other obvious method works either. But this is what I'm doing.

<td class="left"><select class="textbar" name="dtd">
<option value="<? include ("loose.inc")?>">Transitional</option>
<option value="<? include ("strict.inc")?>">Strict</option>
<option value="<? include ("frameset.inc")?>">Frameset</option>
</select></td>

On submit the correct DTD is put in plain text on a new page. All the other elements of the form work it's just getting all the characters of a DTD to work.

I really do appreciate all the help.

Birdman

3:33 am on Mar 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$html4 = htmlentities [php.net]("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http:// www.w3.org/TR/html4/ strict.dtd\">";

<option value="<?=$html4?>">Transitional</option>

Oaf357

4:01 am on Mar 8, 2003 (gmt 0)

10+ Year Member


I have such a headache.

Umm... this isn't working in my script:

<?
$strict = htmlentities("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http:// www.w3.org/TR/html4/ strict.dtd\">";
?>

<option value="<?=$strict?>">Transitional</option>

I don't think I'm doing it right

aspr1n

9:19 pm on Mar 9, 2003 (gmt 0)

10+ Year Member



Oaf357, p'raps I'm misunderstanding your problem here, but there are only 1/2 dozen or so DTDs that you can pick from so a simple switch\case senario leading to printf() would work fine.

If you want the doctype actually readable as html then it's simply:

printf('&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;')

P'raps you could re-explain the problem you are having, as as I understand it I don't see an issue?

asp

Oaf357

9:44 pm on Mar 9, 2003 (gmt 0)

10+ Year Member


<<< If you want the doctype actually readable as html then it's simply:... >>>

want it readable as text. NOT HTML, because as you said, that's easy. I want it to actually display on the page in PLAIN TEXT the DTD itself.

aspr1n

11:57 am on Mar 10, 2003 (gmt 0)

10+ Year Member



I want it to actually display on the page in PLAIN TEXT the DTD itself.

..as in the whole DTD itself (not just the doctype) printed to the page?

I'm not sure what you mean by "plain text", the DTD is just XML? Perhaps you could paste a sample here of what the html page would look like?

asp

rfontaine

1:58 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

!

Oaf357

8:24 pm on Mar 10, 2003 (gmt 0)

10+ Year Member


As I've said &gt; and &lt; does not work in PHP. If it did this issue would be solved.

This is a DTD:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

I'd like it to be an include that will display the DTD is its entirity as text.

rfontaine

9:53 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



Yes, just do an include like:

<?php
include 'show_doctype.php';
?>

And then make this as show_doctype.php file:

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

Thats it. No other code needed. The doctype will be printed literally on the page. If you want to show different doctypes according so some logic, use switches or if's

aspr1n

10:02 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



I'm sorry Oaf357,

But I don't understand what you mean by "text". If you mean you want the browser to render the doctype it as normal text in a webpage, then...

As I've said &gt; and &lt; does not work in PHP. If it did this issue would be solved.

procedually generating &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt as discussed via printf() does work fine.

If you want the doctype to be rendered as part of a parsable html document then again the solution has already been presented.

If you want to show the entire contents of the strict DTD as if you had typed: [w3.org ] into you web browser, then that's nothing to do with PHP, the server is probably configured to send the mime type as either text/plain or text/xml. Once you attempt to embed that content inside HTML tags it becomes html as far as the browser is concered, and thus will be rendered as such.

If you are content to render the above doc from your local server rather than the above discussed URL then just load the text of the doc into a variable (use fopen()) and use printf() again.

asp

Oaf357

10:13 pm on Mar 10, 2003 (gmt 0)

10+ Year Member



Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in /home/virtual/site63/fst/var/www/html/dev.shortfamilyonline.com/pagestarter/test.php on line 2

Came from:

<?php
printf (&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt)
?>

But that is pretty much what I want to do. Generate the doctype as plain text on a web page.

aspr1n

12:10 pm on Mar 11, 2003 (gmt 0)

10+ Year Member



Oaf357,

printf (&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt)

Firstly You haven't converted the " to the html entity &quot

Secondly the printf() string is encapsulated by quotes.

In your case as you have nothing to evaluate inside the quotes you would use ' instead of "

Thus:

printf('&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;&quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;')

asp

Oaf357

4:55 pm on Mar 11, 2003 (gmt 0)

10+ Year Member



That works splendidly in a standalone PHP script but for some reason won't work in the form or as an include. Why is that?