• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP入门级别代码

php 搞代码 3年前 (2022-01-22) 24次浏览 已收录 0个评论

实例1:第一个PHP程序

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>第一个PHP程序</title></head><body><?phpecho "第一个PHP程序";?></body></html>

运行结果:

实例2:输出日期

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>中文输入</title></head><body><pstyle="margin-top:10px;margin-left:180px"><?phpecho "<font color='#11ffff00'>北京时间:".date("Y-m-d H:i:s ")."</font>"?></body></html>

运行结果:

注意事项:

修改php.ini的配置如下。

[Date]

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

date.timezone ="Asia/Hong_Kong"

然后重启Apache服务,否则显示的将是格林威治时间。

实例3:输出中文

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>输出中文</title></head><body><?phpecho "PHP欢迎你";?></body></html>

运行结果:

实例4:输出图片

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&qu<strong>2本文来源gaodaima#com搞(代@码$网6</strong><pre>搞gaodaima代码

ot;><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>输出图片</title></head><body><?phpecho '<img src="images/PHP参考手册.png" width="1200" height="800" />'?></body></html>

运行结果:

实例5:输出字符串

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>输出字符串</title></head><body><?phpecho "输出字符串";?></body></html>

运行结果:

实例6:输入多个字符串

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/><title>发布最新公告信息</title></head><body><pstyle="margin-top:10px;margin-left:180px"><?phpecho "<font color='#11FF00'>从即日起,登录本站的用户可免费下载手机铃声!"."[".date("Y-m-d H:i:s")."]</font>";?></body></html>

运行结果:


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP入门级别代码

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址