First experience with PHP, first experience with love_PHP tutorial

WBOY
Release: 2016-07-12 08:50:23
Original
937 people have browsed it

First experience with PHP, first experience with love

1. Introduction to related content

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互联网开发 互联网:传统互联网、移动互联网 互联网开发:前端开发(前台)、后台开发(后端、服...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!