实例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> <?php echo "第一个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"> <?php echo "<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> <?php echo "PHP欢迎你"; ?> </body> </html>
运行结果:
实例4:输出图片
<!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> <?php echo '<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> <?php echo "输出字符串"; ?> </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"> <?php echo "<font color='#11FF00'>从即日起,登录本站的用户可免费下载手机铃声!"."[".date("Y-m-d H:i:s")."]</font>"; ?> </body> </html>
运行结果: