473,326 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Validate html with php also

170 100+
How do I go about validating a page of html when it contains php within? Because the validators pick up lots of errors like missing </title> tag. It's there but within php. Any ideas?
May 25 '08 #1
15 1484
Atli
5,058 Expert 4TB
How about executing the file, as a HTTP server would, and validating the output?
In the end, that is what your client will be seeing, so that is what you should be validating anyways.
May 25 '08 #2
beary
170 100+
How about executing the file, as a HTTP server would, and validating the output?
In the end, that is what your client will be seeing, so that is what you should be validating anyways.
Yeah can do that. Just would get a little tedious having to view source, copy and paste each time into a validator. Especially with 100+ files. But if that's the only option, I'll do it.

Thanks.
May 25 '08 #3
TheServant
1,168 Expert 1GB
Yeah can do that. Just would get a little tedious having to view source, copy and paste each time into a validator. Especially with 100+ files. But if that's the only option, I'll do it.

Thanks.
What validator are you using? You could use online one's and just enter in your webpage that has the final output. So no view source required.
May 26 '08 #4
beary
170 100+
What validator are you using? You could use online one's and just enter in your webpage that has the final output. So no view source required.
Yeah I thought of that too. But almost all of the pages on the site are session password protected, so the validator won't touch them. I actually took some time and chose one of my pages to validate. There were like 397 warnings to begin with. But it turned out that most were repeats of about 3 or 4 errors (eg. <tr> instead of </tr> There were so many because the php generating the html had the wrong end tag, for instance. So I fixed them all up and got the page to validate transitional. So I figure if I check for those same errors on all my pages, then they should all be fairly close at the minimum.
May 26 '08 #5
coolsti
310 100+
Something to keep in mind if you are needing to make a lot of HTML pages in your work and you know a bit of OOP.

When I started off with PHP and the applications I built for my company, I very quickly got tired of trying to create the HTML part of the pages correctly, matching TABLE, TR and TD tags and making sure they were in the correct order and did not overlap each other. So I created a few classes that take care of all this tag bookkeeping for me, so I now set up a page by instantiating objects and calling the objects functions to build up the page, and then finally printing the page. I also made a class that produces the main page components (HEADER, TITLE, BODY tags, etc.) so the one thing I do not have to worry is the syntactic correctness of my HTML. Except for the mistakes that I have programmed into the classes, but at least my tags always match and are in the correct order :)
May 26 '08 #6
hsriat
1,654 Expert 1GB
How do I go about validating a page of html when it contains php within? Because the validators pick up lots of errors like missing </title> tag. It's there but within php. Any ideas?
Download this plugin toolbar for Firefox. It has an option to Validate Local HTML. Use that. It will automatically save the client side HTML in a file, upload it to the w3 validator and get its validation done.

Regards,
Harpreet
May 26 '08 #7
hsriat
1,654 Expert 1GB
There were like 397 warnings to begin with. But it turned out that most were repeats of about 3 or 4 errors (eg. <tr> instead of </tr> There were so many because the php generating the html had the wrong end tag, for instance. So I fixed them all up and got the page to validate transitional. So I figure if I check for those same errors on all my pages, then they should all be fairly close at the minimum.
The w3 validator also cleans your markup if you tell it to do so.
........So I created a few classes that take care of all this tag bookkeeping for me, so I now set up a page by instantiating objects and calling the objects functions to build up the page, and then finally printing the page. I also made a class that produces the main page components (HEADER, TITLE, BODY tags, etc.) so the one thing I do not have to worry is the syntactic correctness of my HTML......
Same here, but I don't use class, but procedural function with some necessary arguments which is called where required.
What validator are you using? You could use online one's and just enter in your webpage that has the final output. So no view source required.
I guess this is the only validator used for mark up validation. But in case your page is authorized only to be viewed by the logged in user, then how do you expect validator to read that file and validate the mark up?
May 26 '08 #8
Atli
5,058 Expert 4TB
I use templates, which I have PHP load and replace keywords before printing.
I got all of this wrapped up in a nice, little, easy to use, class :)

So I can just validate the templates when I make them.

I'd recommend some system like that. Makes everything easier.
May 26 '08 #9
beary
170 100+
Coolsti, hsriat and Atli

Thanks all of you for your ideas about this. I've downloaded the FF extension and will look into it. I'm quite interested in using OOP and classes etc to simplify the process, but am not overly sure where to begin. Any suggestions? Basically every page on my site(s) has the same header, page, footer structure, so anything to simplify it would be great.

I have a good knowledge of php and html, reasonable but improving knowledge of css and good knowledge of mysql.

Thanks again so far.
May 27 '08 #10
beary
170 100+
Download this plugin toolbar for Firefox. It has an option to Validate Local HTML. Use that. It will automatically save the client side HTML in a file, upload it to the w3 validator and get its validation done.

Regards,
Harpreet
Thankyou. This is brilliant!
May 27 '08 #11
hsriat
1,654 Expert 1GB
Coolsti, hsriat and Atli

Thanks all of you for your ideas about this.
You forgot about TheServant. He made an equal contribution. ;)

.... Any suggestions? Basically every page on my site(s) has the same header, page, footer structure, so anything to simplify it would be great
Learning OOP is a good thing, but for the time, as you say you have same header, page etc, make an HTML file say template_functions.php and make few functions in it. Say, print_header($title, $js_array, $css_array, ..... ... )
When called, print the header html. Use the attributes for giving title, for calling scripts and css style sheets. Similarly the other functions for page layout and footer.
eg.
Expand|Select|Wrap|Line Numbers
  1. function print_header($title, $js_array, $css_array, $body_class, $onload)
  2. {
  3.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
  4. <html xmlns=\"http://www.w3.org/1999/xhtml\">
  5. <head>
  6. <title>".$title."</title>";
  7.     foreach ($js_array as $js)
  8.         echo "
  9. <script type=\"text/javascript\" src=\"".$js."\"></script>";
  10.     foreach ($css_array as $css)
  11.         echo "
  12. <link href=\"".$css."\" rel=\"stylesheet\" type=\"text/css\" />";
  13.     echo "
  14. </head>
  15. <body class=\"".$body_class."\"";
  16.     if (!!$onload) echo " onload=\"".$onload."\"";
  17.     echo ">";
  18. }
May 27 '08 #12
TheServant
1,168 Expert 1GB
You forgot about TheServant. He made an equal contribution. ;)
Cheers mate.

[ignore]The message you have entered is too short.[/ignore]
May 27 '08 #13
hsriat
1,654 Expert 1GB
You really didn't need to do that ignore thing. Just give too many spaces between the words ;)
May 27 '08 #14
beary
170 100+
He he. Sorry about that TheServant. Guess I would have been better off saying "Thanks all".

Anyway, all the help on this forum is really appreciated!

Cheers
May 27 '08 #15
coolsti
310 100+
Referring to your earlier question about OOP and how to get started:

OOP is not really essential, as just about anything you can do with a class you can also do with functions. It is just far easier using OOP and makes for much better organized code. And you can use OOP in your applications to various degrees. So it definitely is worth learning it and using it in your PHP, and you can use more and more as you learn it and get better at it.

PHP may not be the best place to learn about OOP since the rules in PHP is very relaxed, and you will not learn good OOP coding practice here. If you already know another object oriented language like C++ or Java, that is perhaps better to first read about what OOP is all about. On the other hand, if your main task is to program PHP, there is little reason to stop everything and learn another software language just to pick up the OOP basics; I would say just stick to PHP in that case, and start off by using the online PHP documentation. Just remember that PHP is very relaxed, and you will be breaking a lot of rules in other languages if you do your PHP OOP coding like I do :)

Good luck!
May 27 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Dean Speir | last post by:
Hi... I've been referred to this Newsgroup by the W3C Markup Validator FAQ. I've been happily using this Validator <http://validator.w3.org> for the past 18 months with great success, but...
4
by: Mr. x | last post by:
Hello, I know about the validator on : http://validator.w3.org , which can validate html pages. I just new to this validator. How can I validate (if it can be - by this validator) aspx pages,...
5
by: Jim Heavey | last post by:
When should you use the Page.Validate() method? I thought you would use this method if you have some Server side validation (CustomControl's) you wanted to use and this would cause them to be...
3
by: Martin | last post by:
Hi, I am implemeting a form in asp.net. The form is quite large and the validation is reasonably complex, so I have decieded to implement my own validation rather than use any custon...
3
by: Mike Logan | last post by:
How do I validate messages? If my schema has a simpleType with facets like "minExclusive" and "maxLength" will the .Net framework validate the message before running the web service? This is what...
2
by: John H | last post by:
Hi, How can i just use the XmlDocument object to validate an xml instanace against a schema referenced inside the xml instance? The Load method seems to not validate it against the schema. ...
11
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function...
26
by: webrod | last post by:
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...
1
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
0
by: Lars Eighner | last post by:
In our last episode, <004f629c$0$10265$c3e8da3@news.astraweb.com>, the lovely and talented mark4asp broadcast on comp.infosystems.www.authoring.html: I have not done this, not even on...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.