예제 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]
; 날짜 함수에 사용되는 기본 시간대를 정의합니다.
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" style="max-width:90%" style="max-width:90%" / alt="PHP 엔트리 레벨 코드" >' ?> </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>
실행 결과: