You are here: Re: Tool to validate HTML code with PHP tags? « PHP Programming Language « IT news, forums, messages
Re: Tool to validate HTML code with PHP tags?

Posted by webrod on 04/29/07 08:33

> You want something to 'fix' the HTML code for you,

Yes, but only the HTML code that I have written in the php page.

> It's easy enough to say, use the w3c validator and fix the HTML
> yourself!

That's what I don't want to do ;-)

> The tool you want would have to interpret PHP

Nooooooo (but I guess my english is too bad, so nobody understand me :
(

>and then 'validate' the *output* of your PHP script,

Nooooooo, I don't care about the output :(

> and then somehow figure out where in the script
> the
> error came from... There are so many ways PHP can generate HTML,

No, no, definetely not, and PHP *will not generate HTML*.

>this would require a HUGE amount of intelligence. It would have to figure
> out
> how and where the HTML came from.

No, again. Actually, TIDY does it but with bugs


> The number of ways PHP (or any program) can generate HTML (or anything
> else) is infinite.
No, if you think in terms of XHTML validation. Definetely not.

> No tool can be that smart.
Yes of course. TIDY team could fix their bugs or I could even do the
tool myself but I do not have time to spend with that, unfortunatelly.

> I suppose it could be done if combined with some template based
> programming
> discipline, but it'd be easier to use the w3c validator to find the
> errors, and your
> knowledge of your script to figure out where that error came from.

Yes of course, but I am trying to figure how to avoid it.
If there is no solution, I will do it myself of course. I am just
looking for this tool, it could help now and in the future.

Now to explain why I am saying that php is not generating HTML, and
why I don't care about php code.
Here is an example of a code IN THE PHP page (this is not the output)

<?php for ($i=1;$i<=10;$i++) {?>
<img src="<?php echo $fileName[$i]?>" >
<a href="<?php echo $link[$i]?>" > <?php echo $fileName[$i]?> </a>
<br>
<?php } ?>

A clever tool could say: OK, I don't care about php code, even if PHP
is generating HTML, I don't care!!
I don't want to validate XHTML output!!!!! (I DO NOT CARE ABOUT THE
OUTPUT) . I just want to validate the XHTML in the PHP page.
SO it could translate this like that
//REMOVED PHP TAG
<img src="//REMOVED PHP TAG" >
<a href="//REMOVED PHP TAG"> //REMOVED PHP TAG <br>
//REMOVED PHP TAG

then it could replace like that (by removing PHP code)
<img src="" >
<a href=""> </a><br>

it could say now:
warning: alt is missing in the IMG tag
warning: IMG tas is not closed
warning: BR tag is not closed

Then it could update and provide:
<img src="" alt=""/>
<a href=""> </a> <br/>

Then It will put the code back:
//REMOVED PHP TAG
<img src="//REMOVED PHP TAG" alt="" />
<a href="//REMOVED PHP TAG"> //REMOVED PHP TAG </a> <br/>
//REMOVED PHP TAG

then:
<?php for ($i=1;$i<=10;$i++) {?>
<img src="<?php echo $fileName[$i]?>" alt="" />
<a href="<?php echo $link[$i]?>" > <?php echo $fileName[$i]?> </a>
<br/>
<?php } ?>

Do you see now what I mean? Tidy does this work, but unfortunatelly
with some bugs.
This is easy to do, just an algorithm. Everybody who writes a
compilator one day know how it is easy (grammar etc etc).

Of course, this is easy because your are inserting PHP code in HTML
tags, which is the best solution to do.
When you are developping, If you separate the layers you have 2 php
pages for each page:
page1=> contains only php code (business layer)
page2 included at the end of page1 => contains ONLY HTML code with a
few php code ike "echo, if, while". The main rule is to put php within
HTML tags (like my example). The php code outside should never
generates HTML code. It should only be there to increment a loop or to
manage a loop.

Of course when I write this:
<?php for ($i=1;$i<=10;$i++) {?>
<img src="<?php echo $fileName[$i]?>" >
<?php } ?>

If you say that php is generating HTML code because it is repeating 10
times the <img> tag, then I understand why you don't understand what I
say!!
In this example I do not consider that PHP is really generating HTML
(it is repeating HTML code wich is *NOT* the same thing).
If you write this:
<?php echo"<img src="$fileName[$i]" >"
Then, php is genrating HTML code!! Everybody should avoid this, but
this is only my opinion.

The fact that PHP is repeating a line is not a problem with HTML
validation, because, if you are validating the HTML line (only 1),
then even if you duplicate this line ten times, the validation will
remain OK (maybe with some exceptions??).

That's why again I say it is easy. I really think you can validate
this:
<?php for ($i=1;$i<=10;$i++) {?>
<img src="<?php echo $fileName[$i]?>" >
<a href="<?php echo $link[$i]?>" > <?php echo $fileName[$i]?> </a>
<br>
<?php } ?>

without validating this:
<img src="file1" >
<a href="file1"> file1</a> <br>
<img src="file2" >
<a href="file2"> file2</a> <br>
<img src="file3" >
<a href="file3"> file3</a> <br>
<img src="file4" >
<a href="file4"> file4</a> <br>
.......... etc etc

Rod

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация