Home > Article > Backend Development > PHP entry level code
Example 1: The first PHP program
<!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>
Run result:
##Example 2: Output date<!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>Run result : Notes: Modify the configuration of php.ini as follows. [Date]; Defines the default timezone used by the date functions; http://php.net/date.timezonedate .timezone ="Asia/Hong_Kong"Then restart the Apache service, otherwise the displayed time will be Greenwich Mean Time. Example 3: Output Chinese
<!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>Run result: Example 4: Output picture
<!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" style="max-width:90%" style="max-width:90%" / alt="PHP entry level code" >' ?> </body> </html>Run result:
##Example 5: Output string
<!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>
Run result:
Example 6: Enter multiple strings
<!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>
Running results: