如何使用 W3C.org 验证 PHP 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2987116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:20:08  来源:igfitidea点击:

How to validate a PHP file with W3C.org

phpvalidationfilew3c

提问by Mubeen

I want to validate my PHP project to meet the W3C standard. Can some one explain how to do the PHP file validation using W3C.org?

我想验证我的 PHP 项目是否符合 W3C 标准。有人可以解释如何使用 W3C.org 进行 PHP 文件验证吗?

Is it possible to validate PHP files from the linux console?

是否可以从 linux 控制台验证 PHP 文件?

回答by Andrew Moore

You do not validate the PHP file on the W3C Validator. What the validator validates is the (X)HTML markup, the output of your PHP pages.

您不会在 W3C 验证器上验证 PHP 文件。验证器验证的是 (X)HTML 标记,即 PHP 页面的输出

If your PHP project is hosted on the net, simply give the URL to the validator.

如果您的 PHP 项目托管在网络上,只需将 URL 提供给验证器。

If your PHP project is hosted locally, you will have to save the output to a text file and upload this to the validator. To do this, from your browser, open the "File"menu and choose "Save Page As"... (or press CTRL+ S).

如果您的 PHP 项目在本地托管,则您必须将输出保存到文本文件并将其上传到验证器。为此,请从浏览器中打开“文件”菜单并选择“页面另存为”...(或按CTRL+ S)。

Alternatively, there are a variety of validator plugins available for your browser. Here are some for Firefoxand Chrome.

或者,您的浏览器有多种验证器插件可用。这里有一些适用于FirefoxChrome

回答by Eric Mickelsen

W3C doesn't standardize php, so you can't validate the php files themselves. But, to validate the HTML or XHTML content of your site, just paste the url into the W3C validator.

W3C 没有标准化 php,所以你不能自己验证 php 文件。但是,要验证站点的 HTML 或 XHTML 内容,只需将 url 粘贴到 W3C验证器中即可

回答by Justin B

Andrew Moore is correct but I would like to add one piece of info. for others who hove come across this issue. When hosting locally(like when I use XAMPP) just copy all of the rendered code that is in the browser by right-clicking in the browser and choosing View Page Source (FireFox) or View Source (IE). Then highlight and copy all of the code. After that past that code into the 'Validate by Direct Input' section of the W3C validator side (http://validator.w3.org/#validate_by_input) and press 'Check'. It has worked every time for me.

安德鲁摩尔是正确的,但我想添加一条信息。对于遇到此问题的其他人。在本地托管时(如我使用 XAMPP),只需在浏览器中右键单击并选择查看页面源代码 (FireFox) 或查看源代码 (IE),即可复制浏览器中所有呈现的代码。然后突出显示并复制所有代码。之后,将该代码输入 W3C 验证器端 ( http://validator.w3.org/#validate_by_input)的“通过直接输入验证”部分,然后按“检查”。它每次都对我有用。

回答by Dan H

W3C validates client side markup content, like XHTML, CSS, HTML, etc. It does notvalidate server side content like PHP.

W3C 验证客户端标记内容,如 XHTML、CSS、HTML 等。它不验证服务器端内容,如 PHP。

So, you can validate the output of your PHP pages, not the PHP code itself.

因此,您可以验证 PHP 页面的输出,而不是 PHP 代码本身。

回答by Paresh Patil

You can't validate PHP code on W3C validator, You only validate HTML & CSS code. Steps for W3C validation: (1) First take the input of that PHP code which will be in HTML. Or (1) Go to your website which you want to validate and right click on the screen and select "View Source" or press "CTRL + U". (2) Copy that code and paste it in your editor in any txt file on your computer. (3) Go to https://validator.w3.org/#validate_by_uploadand upload that file where your saved your code. Or (3) Go to https://validator.w3.org/#validate_by_inputand paste your code here. (4) Click on "Check" button. (5) You will see some errors & warnings of the code. Solve it and your code will become W3C validate.

您无法在 W3C 验证器上验证 PHP 代码,您只能验证 HTML 和 CSS 代码。W3C 验证步骤: (1) 首先输入 HTML 格式的 PHP 代码。或者 (1) 转到您要验证的网站并右键单击屏幕并选择“查看源代码”或按“CTRL + U”。(2) 复制该代码并将其粘贴到编辑器中的计算机上的任何 txt 文件中。(3) 转到https://validator.w3.org/#validate_by_upload并上传您保存代码的文件。或者 (3) 转到https://validator.w3.org/#validate_by_input并在此处粘贴您的代码。(4) 单击“检查”按钮。(5) 您会看到代码的一些错误和警告。解决它,您的代码将成为 W3C 验证。