PHP文件及运行(适合PHP初学者)
<h3 style="color: black; text-align: left; margin-bottom: 10px;">PHP文件及运行(适合PHP初学者)</h3>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP文件可<span style="color: black;">包括</span>HTML、JavaScript代码和 PHP代码,换句话说PHP 代码<span style="color: black;">能够</span>嵌入HTML文档。PHP文件名以php为后缀。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP代码以“<?php”开头,以“?>”结束,中间为php代码,代码行都<span style="color: black;">必要</span>以分号结束。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当解析一个文件时,PHP(Hypertext Preprocessor超文本预处理器) 会寻找<span style="color: black;">初始</span>和结束标记,<span style="color: black;">亦</span><span style="color: black;">便是</span> <?php 和 ?>,这告诉 PHP <span style="color: black;">起始</span>和停止解析二者之间的代码。此种解析方式使得PHP <span style="color: black;">能够</span>被嵌入到<span style="color: black;">各样</span><span style="color: black;">区别</span>的文档中去,而任何<span style="color: black;">初始</span>和结束标记之外的部分都会被 PHP 解析器忽略。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP文件例子:aa.php,其内容如下:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> //<span style="color: black;">这儿</span><span style="color: black;">能够</span>写任何php代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo "2*3=";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo 2*3;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><head></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><title><?php echo "这是网页标题"; ?></title></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></head></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> //<span style="color: black;">这儿</span><span style="color: black;">亦</span><span style="color: black;">能够</span>写任何php代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo "\n"; //输出换行</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "2-3=";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> echo 2-3;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 语句以分号结尾(;)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP 支持三种注释:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">// 这是单行注释</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"># 这<span style="color: black;">亦</span>是单行注释</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">/*这是多行</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">注释示例</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">*/</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">php文件中<span style="color: black;">亦</span><span style="color: black;">能够</span>调用其他.php文件</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">include ("文件路径");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">或</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">require ("文件路径");</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">区别require引入文件不存在,脚本会停止,include的话会继续运行。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">关于这点<span style="color: black;">这里</span>不做深入介绍。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">怎样</span>运行PHP代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1、</span>以服务端脚本方式运行</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这是 PHP 最传统,<span style="color: black;">亦</span>是最<span style="color: black;">重点</span>的<span style="color: black;">目的</span><span style="color: black;">行业</span>。<span style="color: black;">必须</span>具备以下三点:PHP 解析器、web 服务器和 web 浏览器。PHP 代码在服务器上执行,结果以纯 HTML 形式返回给浏览器。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这种方式<span style="color: black;">必须</span>配置web服务器和PHP解析器。 Wamp集成Apache/MySQL/PHP/PhpMyadmin,免去了<span style="color: black;">研发</span>人员将时间花费在繁琐的配置环境过程,安装<span style="color: black;">亦</span>比较简单。方便<span style="color: black;">运用</span>者在自己的 PC 机上<span style="color: black;">创立</span> PHP运行环境。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>步:下载Wampserver</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">warmserver<span style="color: black;">供给</span>了php运行的环境,请下载安装。下载Wampserver<span style="color: black;">位置</span>:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><a style="color: black;"><span style="color: black;">http://www.</span><span style="color: black;">wampserver.com/</span></a></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">第二步:写php文件,用记事本或notepad++文本编辑器写,一段简单的php代码如下</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><!DOCTYPE html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "Hello World!";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></body></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"></html></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">或</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?php</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">echo "Hello World!";</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">?></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">能够</span>把这个文件暂时<span style="color: black;">保留</span>在桌面。<span style="color: black;">重视</span>文件后缀为.php,如new1.php。在<span style="color: black;">运用</span>记事本程序编辑PHP文档的过程中,<span style="color: black;">必须</span><span style="color: black;">重视</span><span style="color: black;">保留</span><span style="color: black;">办法</span>和技巧。在“另存为”对话框中输入文件名<span style="color: black;">叫作</span>,后缀名为.php,<span style="color: black;">另一</span>,“<span style="color: black;">保留</span>类型”设置为“所有文件”<span style="color: black;">就可</span>。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">第三步:打开Wampserver ,找到Wampsertver的图标,左键,找到www目录,单击</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-3f1b2c88301c924da30d50097c345e76_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
谷歌网站排名优化 http://www.fok120.com/ 在遇到你之前,我对人世间是否有真正的圣人是怀疑的。 楼主的文章非常有意义,提升了我的知识水平。 “BS”(鄙视的缩写) 百度seo优化论坛 http://www.fok120.com/ “NB”(牛×的缩写,表示叹为观止)
页:
[1]