Home  >  Article  >  Backend Development  >  PHP entry level code

PHP entry level code

巴扎黑
巴扎黑Original
2016-12-28 17:45:561132browse

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:

PHP entry level code

##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=&#39;#11ffff00&#39;>北京时间:".date("Y-m-d H:i:s ")."</font>"
?>
</body>
</html>

Run result :

PHP entry level code

Notes:

Modify the configuration of php.ini as follows.

[Date]

; Defines the default timezone used by the date functions

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

date .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:

PHP entry level code

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 &#39;<img  src="images/PHP参考手册.png"    style="max-width:90%"  style="max-width:90%" / alt="PHP entry level code" >&#39;
?>
</body>
</html>

Run result:

PHP entry level code##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:

PHP entry level codeExample 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=&#39;#11FF00&#39;>从即日起,登录本站的用户可免费下载手机铃声!"."[".date("Y-m-d H:i:s")."]</font>";
?>
</body>
</html>

Running results:

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn