• 0

Is it Standards Compliant to mix HTML and PHP?


Question

21 answers to this question

Recommended Posts

  • 0

What standard are you talking about? If you're asking about HTML standards then it doesn't matter what server side technology (PHP, ASP.net, Python) is used because the clients browser doesn't receive it, only the output of those programs/scripts.

  • 0

What standard are you talking about? If you're asking about HTML standards then it doesn't matter what server side technology (PHP, ASP.net, Python) is used because the clients browser doesn't receive it, only the output of those programs/scripts.

I am talking about HTML standards. I just want to make sure that it remains fully compliant. I am working on a CMS and being able to mix the two will make it much easier to create the system. Also, would you recommend that route or maybe using AJAX to implement it? It will be a basic CMS system, but I want it to be able to refresh content on the page without redirecting the user.

  • 0

Me thinks you've got your terms a bit mixed up. PHP will generate HTML, you won't see the PHP in the final markup. HTML standards compliance is a bit of a mixed bag these days, in general people are more concerned about making sure the markup works cross browser than strict adherence to standard, mostly because a lot of HTML 5 features aren't standardized yet.

The main thing to do when using PHP to generate HTML is to separate out the logic from the markup, so that if someone else wanted to redesign or reuse the HTML code, they wouldn't have to sort out all of the PHP to do so.

  • Like 1
  • 0

Me thinks you've got your terms a bit mixed up. PHP will generate HTML, you won't see the PHP in the final markup. HTML standards compliance is a bit of a mixed bag these days, in general people are more concerned about making sure the markup works cross browser than strict adherence to standard, mostly because a lot of HTML 5 features aren't standardized yet.

The main thing to do when using PHP to generate HTML is to separate out the logic from the markup, so that if someone else wanted to redesign or reuse the HTML code, they wouldn't have to sort out all of the PHP to do so.

Ok, so something like:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>PHP Standards Compliant Test</title>
</head>
<body>
<?php require 'form.php';?>
</body>
</html>
[/CODE]

Is that what you mean?

  • 0

Ok, so something like:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>PHP Standards Compliant Test</title>
</head>
<body>
<?php require 'form.php';?>
</body>
</html>
[/CODE]

Is that what you mean?

We can't tell you if it's standard or not cause we don't know what html code the form.php page will generate.

To know if it's standard load the page in Firefox like a client would do and Validate it using a validator.

  • 0

Ok, so something like:


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>PHP Standards Compliant Test</title>
</head>
<body>
<?php require 'form.php';?>
</body>
</html>
[/CODE]

Is that what you mean?

More likely you'd include the form in the HTML, do simple validation with javascript, and use AJAX to send the results to a php file which handles it, then sends some information back which is processed through javascript, with a fallback to do that without javascript.

The way you have it there's probably a form with HTML markup stuck with PHP code.

  • 0

More likely you'd include the form in the HTML, do simple validation with javascript, and use AJAX to send the results to a php file which handles it, then sends some information back which is processed through javascript, with a fallback to do that without javascript.

The way you have it there's probably a form with HTML markup stuck with PHP code.

Ok, so the way that I originally wrote my code would probably be best then? Here is what I had:

news.html:

http://pastebin.com/rB9WgnD2[

ajax.js:

http://pastebin.com/9k1FJq5G

news.php:

http://pastebin.com/dfPtPL6h

  • 0

Just an FYI, alternative syntax makes mixing PHP and HTML easier:

[color=#000000][color=#0000BB]<?php while[/color][color=#007700]([/color][color=#0000BB]$a [/color][color=#007700]== [/color][color=#0000BB]5[/color][color=#007700]): [/color][color=#0000BB]?>[/color]
A is equal to 5
[color=#0000BB]<?php endwhile[/color][color=#007700]; [/color][color=#0000BB]?>[/color] [/color] [/CODE]

also mysql_connect is not a good start... look into mysqli and prepared statements.

Ok, thank you!

  • 0

I decided to proceed with writing my own very basic cms because I don't require a lot of features right away and I want full control of the code. I want to be able to control every aspect of how the system works and have full freedom to modify it. I just have one more quick question. Is it wise to use just one news.js and news.php script and have each page that is displaying news pass in its own category? If not, what would you recommend to generate each page's news? I appreciate all of your help.

  • 0

I decided to proceed with writing my own very basic cms because I don't require a lot of features right away and I want full control of the code. I want to be able to control every aspect of how the system works and have full freedom to modify it. I just have one more quick question. Is it wise to use just one news.js and news.php script and have each page that is displaying news pass in its own category? If not, what would you recommend to generate each page's news? I appreciate all of your help.

Just FYI, if this is for fun, or to learn something, go right ahead. If this is going to end up on the web in some way... I'd argue it's a terrible idea. Basically, you have full control over any framework or CMS if you want it, but you also get the advantage of having someone track down bugs / build in security / make things easier for you, and provide an update path, which is fairly important in PHP.

As for your second question, yes, one script or function will always be better than multiples of them doing the same thing.

  • 0

Just FYI, if this is for fun, or to learn something, go right ahead. If this is going to end up on the web in some way... I'd argue it's a terrible idea. Basically, you have full control over any framework or CMS if you want it, but you also get the advantage of having someone track down bugs / build in security / make things easier for you, and provide an update path, which is fairly important in PHP.

As for your second question, yes, one script or function will always be better than multiples of them doing the same thing.

Ok, thank you. I appreciate the help. It is actually for a church website that I am developing. Are there any good tutorials related for drupal in that case. I have no clue where to even begin. It has to be able to integrate with my website theme as well.

  • 0

Drupal's documentation is pretty good. It might help to pick up a book (I've read through this one, it's good, but save some money and get an e-version) as it will have a good explanation of using views.

Just to clarify, I suggested Drupal because it looked like you were planning on display a lot of information drawn from a database, which Views is great for. I find Wordpress to be easier to use if you're just dealing with posts / pages. Either can be themed, and you can set up a child theme from a template to get up and running faster.

  • 0

Drupal's documentation is pretty good. It might help to pick up a book (I've read through this one, it's good, but save some money and get an e-version) as it will have a good explanation of using views.

Just to clarify, I suggested Drupal because it looked like you were planning on display a lot of information drawn from a database, which Views is great for. I find Wordpress to be easier to use if you're just dealing with posts / pages. Either can be themed, and you can set up a child theme from a template to get up and running faster.

I am planning to display a lot of information actually. It is going to build up over time and consist of news, blog posts, and occasionally a letter from the pastor. In depth content management is very important. If I can get this to work well, it will free up a lot of time for me to create other custom components. Hopefully I can figure out Drupal and make it fit into my site.

  • 0

I am planning to display a lot of information actually. It is going to build up over time and consist of news, blog posts, and occasionally a letter from the pastor. In depth content management is very important. If I can get this to work well, it will free up a lot of time for me to create other custom components. Hopefully I can figure out Drupal and make it fit into my site.

OK... then I would actually suggest Wordpress. :D It will be easier to theme, and easier to get others to add content to if that is ever the case in the future. For that I would recommend a book, as the Wordpress documentation can drive you crazy sometimes, although perhaps someone else can chime in with a good one, as I've sort of picked it up over time.

Drupal is better if you had, for example, a database of all the events for multiple churches in an area, and you wanted to be able to sort the events and see who was going to each event.

  • Like 1
  • 0

OK... then I would actually suggest Wordpress. :D It will be easier to theme, and easier to get others to add content to if that is ever the case in the future. For that I would recommend a book, as the Wordpress documentation can drive you crazy sometimes, although perhaps someone else can chime in with a good one, as I've sort of picked it up over time.

Drupal is better if you had, for example, a database of all the events for multiple churches in an area, and you wanted to be able to sort the events and see who was going to each event.

Well, after thorough research, it looks like I can't run drupal 7 on my godaddy hosting plan. I guess I am stuck coding it myself because I do need the site to be fully enabled for those advanced features at some point. It is going to continually evolve to include new features as time goes on. :) It isn't a news only site. That is just how it is going to be until I am able to add more to it.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I don’t get why if I bought the game on the last get I needed to pay $40 to upgrade to the new version in the first place and people who love the game and play a lot would have upgraded already so this is just PR and a chance to grab new players who forgot the game long time ago I think
    • The term "use" is doing a lot of heavy lifting in that headline. "Use" can mean opening ChatGPT occasionally to ask for the definition of a word or information about a specific topic. If you frame the question around how many people use it as a daily driver in their work or personal lives, that number is a lot smaller. Those are the people who pay for AI. Nearly everyone else is happy to use it for free, but doesn't see enough value in it to pay for it.
    • No support for Windows Hello!
    • I think you meant the "ntfs3" driver, but yes there have been a lot of fixes for it in this release and previous releases, not 100% sure if the issue you mentioned is fixed though. In any case, the new "ntfs" driver in 7.1 doesn't have that issue (at least, no reports of such have come thru), but your kernel needs to explicitly enable support for the new driver first (like how CachyOS kernel has it), and you need to edit your mount points in /etc/fstab to use "ntfs" instead of the other drivers.
    • Epic Games says Unreal Engine 6 will help developers "build content faster" using AI models by Pulasthi Ariyasinghe Epic Games is rolling out the latest major update to Unreal Engine 5 today, and at the same time, the company also dropped some information on the next-generation version of the product, Unreal Engine 6. This was already revealed a few weeks ago alongside the new Rocket League upgrade reveal. The company says it is combining the features of Unreal Engine and Unreal Editor for Fortnite to create this new version of its popular media creation tool. On top of creating entire games, the new engine will also focus on letting developers operate large-scale live service titles more easily, whether by shipping content into their own ecosystems or into Fortnite. The use of large language models is also mentioned here, with Epic saying it will be a core part of the engine. "We see LLMs, generative AI models, and tools like Claude and Codex playing a central role in helping you build content faster while maintaining the creative control you need," adds the company. Here is the rundown of what's new about version 6 of Unreal Engine: With all these changes to the programming model, portability upgrades, and generative AI integration, Epic says the new version of the engine will "change a lot about how games are made." The company aims to ship Unreal Engine 6 into early access in late 2027, with a full release planned for 12-18 months later. Epic Games also dropped a lengthy blog post about the new Unreal Engine 5.8 update for game developers over here. The release is focused on delivering better performance, customization, and streamlined workflows for development teams. This will be the final major update for this version of the engine before Epic switches to focus fully on Unreal Engine 6's early access launch.
  • Recent Achievements

    • One Month Later
      Vincian earned a badge
      One Month Later
    • First Post
      Jocimo earned a badge
      First Post
    • Week One Done
      suprememobiles48 earned a badge
      Week One Done
    • One Month Later
      Windows Guy earned a badge
      One Month Later
    • One Month Later
      Prasann earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      502
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      86
    4. 4
      Steven P.
      67
    5. 5
      neufuse
      65
  • Tell a friend

    Love Neowin? Tell a friend!