Table of Contents
First experience with PHP, first experience with love
1. Introduction to related content
4. Basic PHP syntax
5. PHP实现API接口开发(GET)
6. PHP实现API接口开发(POST)
Home php教程 php手册 First experience with PHP, first experience with love

First experience with PHP, first experience with love

Jul 06, 2016 pm 02:25 PM
php internet introduce experience content front end Backstage develop Related move

First experience with PHP, first experience with love

1>Internet Development

  • Internet: Traditional Internet, Mobile Internet

  • Internet development: front-end development (front-end), back-end development (back-end, server)

  • Front-end development: visual display (user interface), user interaction, collecting input information

  • Backend development: manage and process data, develop interfaces to clients, control output

 2> Client server mode (C/S)

  • Client: actively initiate communication (initiate request), such as browsers, mobile clients, etc.

  • Server: passively waiting for communication (responding to requests), such as: web server, FTP server, mail server, etc.

 3> Web Server Development

Web Server: In a network environment, it provides response services to clients that initiate requests, mainly processing HTTP requests.

1> Environment setup

  • Apache: Web server software, supports most computer operating systems, and is one of the most popular Web server software. Mac system comes with Apache.

  • PHP: A scripting language suitable for Webserver development, cross-platform, supporting most databases and operating systems, mixed with C and Java language syntax, open source code.

  • MySQL: Relational database management system, small in size and fast, widely used in small and medium-sized websites.

2> XAMPP and Coda

  • XAMPP is a software package that integrates the Apache PHP MySQL installation environment. It can be installed with one click, which is convenient and fast.

Coda: a web programming tool for Mac computers with multi-language support (HTML, PHP, JavaScript, CSS, etc.)

3> Web Server Workflow

1> Principle

2> Local server path

3> Access server files

URL format: protocol://domain name/path/query

http://127.0.0.1

Access the root directory of the local web server and load the index file content by default

http://127.0.0.1/File path (including file name and suffix)

Access a file in the root directory of the local web server, such as pictures, php, html

4. Basic PHP syntax

1> PHP tag

<?<span>php

    </span><span>echo</span>("hello lanou");<span>//</span><span> 输出函数</span>

    "<br/>"  <span>//</span><span> 换行</span>

    <span>echo</span> "iOS"; <span>//</span><span> 输出函数,可以不带括号        </span>
    
?>
Copy after login

Reference learning website: http://www.runoob.com/php/php-tutorial.html

2> Variables

Variable definition

Variables start with $, followed by the variable name

Variables are composed of letters, numbers, and underscores, and do not start with numbers

Variable names are case-sensitive

Define automatic type variables

<span>  $int_value</span> = 10<span>;       
  </span><span>$float_value</span> = 1.5<span>;    
  </span><span>$name</span> = "hello lanou";
Copy after login

Get the variable type and return string

<span>  gettype</span>(<span>$name</span>);
Copy after login

3> String

Connection string

    <span>$name</span> = 'iPhone'<span>;
    </span><span>$str</span> = '5'<span>;
    </span><span>$name</span> = <span>$name</span>.<span>$str</span><span>;
    </span><span>echo</span>(<span>$name</span>);
Copy after login

4> if branch

    <span>//</span><span>比较两个变量,输出最大值</span>
    
    <span>$a</span> = 3;<span>$b</span> = 5<span>;

    </span><span>if</span>(<span>$a</span>><span>$b</span><span>){
        </span><span>echo</span>(<span>$a</span><span>);
    }</span><span>else</span><span>{
        </span><span>echo</span>(<span>$b</span><span>);
    }</span>
Copy after login

5> for loop

<span>//</span><span>输出1~10之间所有的数</span>
<span>for</span>(<span>$i</span> = 1;<span>$i</span><=10;<span>$i</span>++<span>){
    </span><span>echo</span>(<span>$i</span>.'<br>'<span>);
}</span>
Copy after login

6> Random number

Generate a random number between a~b rand(a, b)

<span>//</span><span> 生成20~50之间的随机数,并输出</span>
<span>$num</span> = <span>rand</span>(20, 50<span>);
</span><span>echo</span> <span>$num</span>;
Copy after login

7> Array

In PHP, use the array() function to create an array

In PHP, there are three types of arrays:

Numeric array - array with numeric ID keys (similar to NSArray)

Associative array - an array with specified keys, each key is associated with a value (similar to NSDictionary)

Multidimensional array - an array containing one or more arrays

<span>$array1</span> = <span>array</span>();  <span>//</span><span> 空数组</span>
<span>$array2</span> = <span>array</span>(99, 98, 97);  <span>//</span><span> 数值数组    </span>
<span>$array3</span> = <span>array</span>("name"=>"lishuai", "age"<span>=>40);  // 关联数组,键=>值
print_r(</span><span>$array3</span>); // 输出数组内容
Copy after login

8> Numeric array 

The count() function is used to return the number of array elements

<span>$count</span> = <span>count</span>(<span>$array</span><span>);

</span><span>echo</span> <span>$count</span>;
Copy after login

 Add array elements

<span>$array</span>[] = 96;  <span>//</span><span> 数组中最后一个元素</span>
Copy after login

Access array elements

$array[numeric ID key]

Traverse the numerical array

foreach(array as $value){
echo($value."
");
}

    <span>$array</span> = <span>array</span>(12, 13, 14, 15<span>);
    
    </span><span>foreach</span>(<span>$array</span> <span>as</span> <span>$value</span><span>){
    </span><span>echo</span>(<span>$value</span>."<br/>"<span>);
    }</span> 
Copy after login

9> Associative array

      <span>$person</span> = <span>array</span>("name"=>"yihuiyun", &ldquo;age"=>"18"<span>)
      print_r(</span><span>$person</span>);  // 输出
Copy after login

Output result Array ( [name] => yihuiyun [age] => 18 )

<span>$person</span> = <span>array</span>("name"=>"yihuiyun", &ldquo;age"=>"18"<span>)

// count()函数用于返回数组元素的数量

</span><span>$count</span> = count(<span>$person</span><span>);
echo </span><span>$count</span><span>;

//添加键值对

</span><span>$person</span>["sex"] = "female"<span>;  

//根据键获取值

//</span><span>$person</span>[键]
Copy after login

Traverse associative array

   foreach(数组 as $key=>$value){
  echo($key.":".$value."
");
   }

<span>$person</span> = <span>array</span>("name"=>"yihuiyun", &ldquo;age&rdquo;=>&rdquo;18"<span>);

foreach(</span><span>$person</span> as <span>$key</span>=><span>$value</span><span>){
    echo(</span><span>$key</span>.":".<span>$value</span>."<br/>"<span>);
}</span>
Copy after login

 10> json转换

<span>//</span><span> 数组转json字符串</span>
<span>$json</span> = json_encode(<span>$array</span><span>);

</span><span>//</span><span> json字符串转PHP对象</span>
<span>$array</span> = json_decode(<span>$json</span>);
Copy after login

5. PHP实现API接口开发(GET)

 1> 概述

  在 PHP 中,预定义的 $_GET 变量用于收集来自 method="get" 的表单中的值。

  从带有 GET 方法的表单发送的信息,对任何人都是可见的(会显示在浏览器的地址栏),并且对发送信息的量也有限制。

  GET 传值的一个 URL:http://127.0.0.1/get.php?username=lanou&password=123

  解析:http://127.0.0.1/get.php?参数名1=值1&参数名2=值2

   参数名通常由后台规定,前端根据接口文档填写

  PHP文件接收数据代码:

    <span>//</span><span> 获取数据   key必须与参数名保持一致</span>
    <span>$name</span> = <span>$_GET</span>["username"<span>];
    </span><span>$password</span> = <span>$_GET</span>["password"];
Copy after login

 2> iOS网络编程

  代码:

6. PHP实现API接口开发(POST)

 1> 概述

  预定义的 $_POST 变量用于收集来自 method="post" 的表单中的值。

  从带有 POST 方法的表单发送的信息,对任何人都是不可见的(不会显示在浏览器的地址栏),并且对发送信息的量也没有限制

  http://127.0.0.1/post.php

  URL中不需要携带参数,通过body上传参数
  PHP文件接收数据代码:

    <span>//</span><span> 获取数据   key必须与参数名保持一致</span>
    <span>$name</span> = <span>$_POST</span>["username"<span>];
    </span><span>$password</span> = <span>$_POST</span>["password"];
Copy after login

 

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

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

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

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

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 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,

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

See all articles