Tool to validate HTML code with PHP tags?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • webrod

    Tool to validate HTML code with PHP tags?

    Hi,

    I have some php pages with a lot of HTML code.
    I am looking for a HTML validator tool (like TIDY).
    TIDY is not good enough with PHP tags (it removes a lot of php code).

    Do you have any idea?

    Thanks you very much

    Rod

  • Alvaro G. Vicario

    #2
    Re: Tool to validate HTML code with PHP tags?

    *** webrod escribió/wrote (26 Apr 2007 09:04:36 -0700):
    I have some php pages with a lot of HTML code.
    I am looking for a HTML validator tool (like TIDY).
    TIDY is not good enough with PHP tags (it removes a lot of php code).
    PHP is *not* HTML so having problems with an HTML validator is exactly what
    you could expect.

    I presume you want to validate the HTML generated by your PHP script. Just
    load your script through a web server and validate the output with the W3C
    validators:

    W3C's easy-to-use markup validation service, based on SGML and XML parsers.


    You have two options:

    1) If your web is hosted in a public server, feed the validator with the
    URL

    2) If your web is hosted in a local test server, feed it with a file
    upload. Use your browser's "Save as" feature and save it as plain HTML.

    If you Google for "Webdevelop er toolbar" you'll find a Firefox extension
    and an Internet Explorer toolbar; any of them can assist you in validating
    your HTML.

    --
    -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    ++ Mi sitio sobre programación web: http://bits.demogracia.com
    +- Mi web de humor con rayos UVA: http://www.demogracia.com
    --

    Comment

    • Christoph Burschka

      #3
      Re: Tool to validate HTML code with PHP tags?

      webrod wrote:
      Hi,
      >
      I have some php pages with a lot of HTML code.
      I am looking for a HTML validator tool (like TIDY).
      TIDY is not good enough with PHP tags (it removes a lot of php code).
      >
      Do you have any idea?
      >
      Thanks you very much
      >
      Rod
      >
      I see you've posted this message separately to several newsgroups, instead of
      sending it to these newsgroups all at once.

      Firstly, this is a needless effort on your part, and secondly, this means
      responses will only show up on the newsgroup that the response was posted in.
      Check alt.comp.lang.p hp for my answer to your question.

      If you posted this with a News client, just add all the newsgroups you want to
      post to in the recipients above, like you would do with an email to several
      people. If you posted with Google Groups, you can enter several groups in the
      "To Newsgroups" field, separated by commas. This'll save you a lot of work
      otherwise wasted on posting to and checking to all these different groups
      (a.c.p.l, c.p.l, a.p, etc.) :)

      --
      cb

      Comment

      • webrod

        #4
        Re: Tool to validate HTML code with PHP tags?

        oups! thanks you, I didn't know that.
        I thought it was not possible.
        Sorry about that.

        I provide my answer here:

        Hi,

        I guess I was not clear enough.

        I do not want to validate the output of a php page, I want to validate
        the php page itself.
        My php code NEVER provides HTML code. That's a very important rule I
        follow.
        I mean I never do that:
        <?php echo "<a href='$myLink'> go to my link</a>" ?>
        I do that:
        <a href='<?php echo $myLink?>'>go to my link</a>

        Actually I have the main php page which does the business (only PHP
        code, no HTML at all), then I include a template with HTML code + a
        little bit of php code.

        I would like now to find a tool which is able to validate my XHTML
        code (within the template) and udpate the XHTML to be conformed with
        W3C rules.
        For example it should automatically update <brto <br/>.
        TIDY does this work. Unfortunatelly it doesn't like php tags and
        remove a lot of them.

        I would like to work on the templates and not on the output to do the
        job automatically.
        If I work on the output, I have to manually update all the templates!!
        Unfortunatelly I have a lot of templates.

        Do you have an idea?

        thanks

        rod

        Comment

        • Jerry Stuckle

          #5
          Re: Tool to validate HTML code with PHP tags?

          webrod wrote:
          oups! thanks you, I didn't know that.
          I thought it was not possible.
          Sorry about that.
          >
          I provide my answer here:
          >
          Hi,
          >
          I guess I was not clear enough.
          >
          I do not want to validate the output of a php page, I want to validate
          the php page itself.
          My php code NEVER provides HTML code. That's a very important rule I
          follow.
          I mean I never do that:
          <?php echo "<a href='$myLink'> go to my link</a>" ?>
          I do that:
          <a href='<?php echo $myLink?>'>go to my link</a>
          >
          Actually I have the main php page which does the business (only PHP
          code, no HTML at all), then I include a template with HTML code + a
          little bit of php code.
          >
          I would like now to find a tool which is able to validate my XHTML
          code (within the template) and udpate the XHTML to be conformed with
          W3C rules.
          For example it should automatically update <brto <br/>.
          TIDY does this work. Unfortunatelly it doesn't like php tags and
          remove a lot of them.
          >
          I would like to work on the templates and not on the output to do the
          job automatically.
          If I work on the output, I have to manually update all the templates!!
          Unfortunatelly I have a lot of templates.
          >
          Do you have an idea?
          >
          thanks
          >
          rod
          >
          Rod,

          As Alvaro said - http://validator.w3.org.

          How you generate the html (and yes, you are using PHP to generate HTML -
          the link destination in the href is part of html) is unimportant. The
          result is html.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • webrod

            #6
            Re: Tool to validate HTML code with PHP tags?

            As Alvaro said -http://validator.w3.or g.

            No, this validates the output (ok you could provide the php file as an
            input).
            And as I said I would like the tool to do the modification itself.
            Like the great TIDY tool (but it removes php code!!).
            How you generate the html (and yes, you are using PHP to generate HTML -
            the link destination in the href is part of html) is unimportant. The
            result is html.
            Of course the final result is HTML ;-)
            If you consider the output, obviously this is HTML+CSS+Javasc ript
            But if you consider the INPUT, there is 2 ways to build a php page.
            How to say.... They are 2 families of developpers ;-)
            The first family will ask PHP to generate the HTML code (HTML within
            php tag)
            The second family will insert PHP tag within HTML tag.
            And believe me, this is not the same thing, even if, obviously, the
            output is exactly the same HTML.
            (I belong to the second family)

            Any other idea to validate my templates files which contains PHP code
            within HTML tags?

            Rod

            Comment

            • webrod

              #7
              Re: Tool to validate HTML code with PHP tags?

              PHP is *not* HTML

              of course!!
              >so having problems with an HTML validator is exactly what
              you could expect.
              HTML validator means that the HTML will be validated in a page.
              It does not mean that you can only validate a .html file.
              The proof with TIDY. It is able to work with php tags (you even have
              some option to deal with php).
              Unfortunately, it does that badly. A lot of bugs.
              So I am wondering if there is another tool like TIDy but without bugs.
              I use the ZEND IDE but it does not validate HTML code.

              I presume you want to validate the HTML generated by your PHP script.
              Just load your script through a web server and validate the output with the W3C
              validators:
              >
              http://validator.w3.org
              I know this website, but unfortunatelly, it does not automatically
              update the code (for example to update <brto <br/>)
              And it works on the output, not on the input (except if you provide
              the php file but I guess it doesn't like php code. It's not the goal
              of this website to validate XHTML code in a php page)

              Thanks for your help

              Rod


              Comment

              • Jerry Stuckle

                #8
                Re: Tool to validate HTML code with PHP tags?

                webrod wrote:
                >As Alvaro said -http://validator.w3.or g.
                >
                No, this validates the output (ok you could provide the php file as an
                input).
                And as I said I would like the tool to do the modification itself.
                Like the great TIDY tool (but it removes php code!!).
                >
                >How you generate the html (and yes, you are using PHP to generate HTML -
                >the link destination in the href is part of html) is unimportant. The
                >result is html.
                >
                Of course the final result is HTML ;-)
                If you consider the output, obviously this is HTML+CSS+Javasc ript
                But if you consider the INPUT, there is 2 ways to build a php page.
                How to say.... They are 2 families of developpers ;-)
                The first family will ask PHP to generate the HTML code (HTML within
                php tag)
                The second family will insert PHP tag within HTML tag.
                And believe me, this is not the same thing, even if, obviously, the
                output is exactly the same HTML.
                (I belong to the second family)
                >
                No, there is no difference. In either case you are using PHP to output
                information to the page. Nothing more, nothing less. Zip. Nada.

                You are getting lost in the details. Look at the higher level.
                Any other idea to validate my templates files which contains PHP code
                within HTML tags?
                >
                Rod
                >
                So what exactly do you want to validate? The only important things are
                - the PHP code itself is valid (the interpreter will tell you if it's
                not), and the HTML output is valid (which the validator will tell you).

                What exactly do you expect?

                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • webrod

                  #9
                  Re: Tool to validate HTML code with PHP tags?

                  No, there is no difference. In either case you are using PHP to output
                  information to the page. Nothing more, nothing less. Zip. Nada.
                  This is because you are focusing on the outpout. As I said, YES the
                  output is EXACTLY the same, if you compare the generated HTML, I agree
                  this is the same.
                  So what exactly do you want to validate? The only important things are
                  - the PHP code itself is valid (the interpreter will tell you if it's
                  not),
                  I don't care about the PHP code
                  >and the HTML output is valid (which the validator will tell you).
                  Yes. This is what I want.
                  BUT:
                  I don't want to validate the output because I am NOT looking for a
                  tool which only validate the HTML (like "you should replace <brby
                  <br/to be conformed with XHTML rule bla bla bla").
                  I am looking for a tool which will do the job for me ;-)
                  I want it to replace automatically <brby <br/in my php page.
                  I want it to udpate the code. (actually TIDY do it It works even with
                  PHP page but with bugs!!)

                  I'm sure you understand that I need to do this step on the input (the
                  php page) instead of the output (or its work will be lost!!!!!).

                  And then you get a better understanding of the difference between
                  familly 1 and familly 2.

                  Obviously, if you want to validate the output, there is no difference
                  (who said it is what I want?). But if you need to validate the HTML
                  code from a php page, you will understand it will be easier to
                  validate HTML code if the php code is in the HTML (and not the
                  opposite, when HTML is in the php code).
                  And that's why it is always recommended to belong to the second
                  family ;-)

                  Rod

                  Comment

                  • Toby A Inkster

                    #10
                    Re: Tool to validate HTML code with PHP tags?

                    webrod wrote:
                    I don't care about the PHP code
                    Neither does an HTML validator.

                    --
                    Toby A Inkster BSc (Hons) ARCS
                    Fast withdrawal casino UK 2025 – Play now & cash out instantly! Discover the top sites for rapid, secure payouts with no delays.

                    Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

                    * = I'm getting there!

                    Comment

                    • Razzbar

                      #11
                      Re: Tool to validate HTML code with PHP tags?

                      You want something to 'fix' the HTML code for you, like Tidy does. I'd
                      like to say
                      that it's impossible, but of course, it isn't impossible *in theory*.

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

                      The tool you want would have to interpret PHP and then 'validate' the
                      *output*
                      of your PHP script, and then somehow figure out where in the script
                      the
                      error came from... There are so many ways PHP can generate HTML, this
                      would require a HUGE amount of intelligence. It would have to figure
                      out
                      how and where the HTML came from.

                      The number of ways PHP (or any program) can generate HTML (or anything
                      else) is infinite.

                      No tool can be that smart.

                      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.


                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Tool to validate HTML code with PHP tags?

                        webrod wrote:
                        >No, there is no difference. In either case you are using PHP to output
                        >information to the page. Nothing more, nothing less. Zip. Nada.
                        >
                        This is because you are focusing on the outpout. As I said, YES the
                        output is EXACTLY the same, if you compare the generated HTML, I agree
                        this is the same.
                        >
                        Then who cares about how it's generated? I sure don't. You're fixating
                        on the details instead of the overall picture.
                        >So what exactly do you want to validate? The only important things are
                        >- the PHP code itself is valid (the interpreter will tell you if it's
                        >not),
                        >
                        I don't care about the PHP code
                        >
                        Then don't worry about validating the source. Just use the HTML
                        validator to check the output.
                        >and the HTML output is valid (which the validator will tell you).
                        >
                        Yes. This is what I want.
                        BUT:
                        I don't want to validate the output because I am NOT looking for a
                        tool which only validate the HTML (like "you should replace <brby
                        <br/to be conformed with XHTML rule bla bla bla").
                        I am looking for a tool which will do the job for me ;-)
                        I want it to replace automatically <brby <br/in my php page.
                        I want it to udpate the code. (actually TIDY do it It works even with
                        PHP page but with bugs!!)
                        >
                        I'm sure you understand that I need to do this step on the input (the
                        php page) instead of the output (or its work will be lost!!!!!).
                        >
                        And then you get a better understanding of the difference between
                        familly 1 and familly 2.
                        >
                        Obviously, if you want to validate the output, there is no difference
                        (who said it is what I want?). But if you need to validate the HTML
                        code from a php page, you will understand it will be easier to
                        validate HTML code if the php code is in the HTML (and not the
                        opposite, when HTML is in the php code).
                        And that's why it is always recommended to belong to the second
                        family ;-)
                        >
                        Rod
                        >
                        You've got it. It's called "Brain 1.0". And no program has replaced it
                        yet. That's what you get paid for.

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • webrod

                          #13
                          Re: Tool to validate HTML code with PHP tags?

                          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 <imgtag, 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"fil e1</a<br>
                          <img src="file2" >
                          <a href="file2"fil e2</a<br>
                          <img src="file3" >
                          <a href="file3"fil e3</a<br>
                          <img src="file4" >
                          <a href="file4"fil e4</a<br>
                          .......... etc etc

                          Rod

                          Comment

                          • webrod

                            #14
                            Re: Tool to validate HTML code with PHP tags?

                            On 28 avr, 03:13, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                            webrod wrote:
                            No, there is no difference. In either case you are using PHP to output
                            information to the page. Nothing more, nothing less. Zip. Nada.
                            >
                            This is because you are focusing on the outpout. As I said, YES the
                            output is EXACTLY the same, if you compare the generated HTML, I agree
                            this is the same.
                            >
                            Then who cares about how it's generated? I sure don't. You're fixating
                            on the details instead of the overall picture.
                            I don't care about the overall picture in this thread? (and who
                            cares?)
                            So what exactly do you want to validate? The only important things are
                            - the PHP code itself is valid (the interpreter will tell you if it's
                            not),
                            >
                            I don't care about the PHP code
                            >
                            Then don't worry about validating the source. Just use the HTML
                            validator to check the output.
                            And if I don't want?
                            You've got it. It's called "Brain 1.0". And no program has replaced it
                            yet. That's what you get paid for.
                            I'm not paid for that.I've spent a lot of years to develop php website
                            but now I'm .NET architect (so I'm not paid anymore to do php stuffs)
                            I do not have time to spend to manually update my 100 templates php
                            pages because this is to update a personal website.
                            So I'm not paid for, and even If I was, I'm not paid to lost my time.
                            I'm paid to do my job ASAP, I don't want to loose the money of my
                            company because YOU are against automation and tools ;-)

                            OK, so I guess you are paid to write php with Microsoft NOTEPAD
                            because:
                            - you don"t need a tool to validate in real time your php code (you
                            don't care because you have brain 1.0 so you never have errors in your
                            code)
                            - you don't need a tool to debug your code (you don't care because you
                            have brain 1.0 so you never have errors or bugs)
                            - you don't need a tool to provide auto-completion (you know all the
                            php functions, what they do and their parameters thanks to brain
                            1.0..)
                            - you don't need a tool to manage source code (CVS..) even when you
                            work in a team (you have a good communication in the team because you
                            have brain 1.0 , so who cares this tool??)
                            - actually you don't need a tool beacause your get paid for using your
                            brain and not tools(????)

                            Seriously, if you do not know the tool I am looking for, then don't
                            waste your time ;-)

                            Rod



                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstuck...@attgl obal.net
                            =============== ===- Masquer le texte des messages précédents -
                            >
                            - Afficher le texte des messages précédents -

                            Comment

                            • Geoff Berrow

                              #15
                              Re: Tool to validate HTML code with PHP tags?

                              Message-ID: <1177835633.197 048.31470@u30g2 000hsc.googlegr oups.comfrom
                              webrod contained the following:
                              >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??).
                              Lots of exceptions

                              <?php if($something_i s_true){ ?>
                              <div style='border:1 px solid
                              red;padding:20p x;margin:20px;t ext-align:center'>
                              <?php } ?>

                              <?php if($something_e lse_is_true){ ?>
                              <div style='border:1 px solid
                              blue;padding:20 px;margin:20px; text-align:center'>
                              some content
                              </div>
                              <?php } ?>

                              <?php if($something_i s_true){ ?>
                              some more content
                              </div>
                              <?php } ?>

                              OK, you may /never/ code like this. But that's not the point. ASs far
                              as an automated tool is concerned that is perfectly valid code.

                              I can't see how you could possibly check the validity of the code
                              without parsing the php

                              --
                              Geoff Berrow (put thecat out to email)
                              It's only Usenet, no one dies.
                              My opinions, not the committee's, mine.
                              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                              Comment

                              Working...