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 Backend Development PHP Tutorial First experience with PHP, first experience with love_PHP tutorial

First experience with PHP, first experience with love_PHP tutorial

Jul 12, 2016 am 08:50 AM
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.

First experience with PHP, first experience with love_PHP tutorial1> 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.

First experience with PHP, first experience with love_PHP tutorialCoda: a web programming tool for Mac computers with multi-language support (HTML, PHP, JavaScript, CSS, etc.)

First experience with PHP, first experience with love_PHP tutorial 3> Web Server Workflow

First experience with PHP, first experience with love_PHP tutorial1> Principle

First experience with PHP, first experience with love_PHP tutorial 2> Local server path

First experience with PHP, first experience with love_PHP tutorial3> 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

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133563.htmlTechArticlePHP初体验,爱之初体验 1. 相关内容介绍 1互联网开发 互联网:传统互联网、移动互联网 互联网开发:前端开发(前台)、后台开发(后端、服...
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)

Hot Topics

Java Tutorial
1655
14
PHP Tutorial
1252
29
C# Tutorial
1226
24
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

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.

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

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

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.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

See all articles