Home Backend Development PHP Tutorial How to dynamically create a Web site with PHP_PHP tutorial

How to dynamically create a Web site with PHP_PHP tutorial

Jul 21, 2016 pm 03:25 PM
include once php web use function create dynamic external method have of site

PHP has 4 functions for using external functions: include(), include_once(), require() and require_once().
In order to use them, the following lines of code will be included in the PHP script:
include_once(' arr.php');
require('/path/to/filename.html');
The difference between two types of external functions:
It is exactly the same to use, but it will be different when an error occurs : If the include() function does not work, a script will be printed to the web browser, but the script will continue to run. If require() fails, an error will be printed and the script will terminate.
There is also a *_once() version of these two functions, which guarantees that the file being considered will only be included once, regardless of how many times the script may try to include it.
eg:

Copy code The code is as follows:


require('arr1.php');
include('arrsort.php');
?>

Use PHP's binding ability to process HTML forms

require('arr1.php'); //Include the file to be executed first
if(isset($_POST['name'])) //Determine whether to enter, and then execute..
{
$name=$_POST['name'];
echo "$name";
}
?>


黏性表单
预先设置文本框中输入的内容:

让PHP预先设置该值:
;
函数
函数名和变量的命名规则相同,但是函数名不区分大小写。例如:function name() 和function Name()是两个完全相同的函数。
时期和时间函数
date('format',[timestamp]);
依据指定的格式返回某一日期和时间的文本字符串。timestamp是一个可选项,表示正在考虑的日期从Unix Epoch(Unix时间戳,1970年1月1日0点)起所经过的秒数。它允许你获得关于特定日期的信息,如星期几。如果未指定时间戳,PHP就会使用服务器上的当前时间。

字符

含义

示例

Y

4位数字表示年

2005

y

2位数字表示年

05

n

1位或2位数字表示月份

2

m

2位数字表示月份

02

F

月份

February

M

3个字母表示月份

Feb

j

1位或2位表示一月中的某一天

8

d

2位数字表示一月中的某一天

08

l

星期几

Monday

D

用三个字母表示星期几

Mon

g

小时,用1位或2位数字表示的12小时格式

6

G

小时,用1位或2位数字表示的24位小时格式

18

h

小时,用2位数字表示的12小时格式

06

H

小时,用2位数字表示的24小时格式

18

i

45

s

18

a

ampm

am

A

AMPM

AM

可以使用mktime()函数找出特定日期的时间戳。
$stamp=mktime(hour,minute,second,month,day,year);
可以使用getdate()函数返回日期和时间的一组值:
$dates=getdate();
echo $dates['month'];

示例

year

2005

mon

12

month

月份名称

December

mday

一月中的某一天

25

weekday

星期几

Tuesday

hours

小时数

11

minutes

分钟数

56

seconds

秒数

47

eg:
复制代码 代码如下:


function md($m=NULL,$d=NULL,$y=NULL)
{
$months=array(1=>'January','February','March','April','May','June','July','Augst','September','October','November','December');
echo '';
echo '';
echo '';
}
echo '

select a date:


';
$dates=getdate();
md($dates['mon'],$dates['mday'],$dates['year']);
echo '


';
echo '

Today is'.date('l').'. The current time is'.date('H:i a').'.

';
?>


格式化日期函数:
DATE_FORMAT('2005-05-20',%M,%d,%Y);
技巧总结
PHP的日期函数反映了服务器上的事件(因为PHP运行在服务器上);如果想确定客户计算机上的日期和时间,则需要使用javascript;
checkdate()函数带3个参数——月份、天和年份——并检查它是否是一个有效的日期(现在或过去实际存在的日期)。
发送电子邮件
mail($to,$subject,$body);
$to值应该是一个电子邮件地址或一系列地址,中间用逗号隔开。
$subject值将创建电子邮件的主题行,
$body可用于在其中设置电子邮件的内容。
在创建电子邮件正文时,可以在双引号内使用换行符(n),使文本分布在多行上。
$mail()函数带有四个可选参数,用于额外的电子邮件头部。在此可以设置From(发件人)、Reply-To(回复)、Cc(抄送)、Bcc(密件抄送)以及类似的设置。
eg:
mail('fanchangfa@126.com','Question regardingScript 3.13',$body,'From:killman@hotmail.com');
要在电子邮件中使用多个不同类型的头部,可以用rn把他们隔开:
$headers="From:John@hotmail.comrn";
$headers.="Cc:jane@hotmail.com,joe@hotmail.comrn";
mail('fanchangfa@126.com','Question','$body,$headers');

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/324151.htmlTechArticlePHP有4个用于使用外部函数的函数:include()、include_once()、require()和require_once(). 为了使用它们,PHP脚本中将包括如下代码行: include_once('arr...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles