search
HomeBackend DevelopmentPHP TutorialFirst 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
phpinternetintroduceexperiencecontentfront endBackstagedevelopRelatedmove

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

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";

Get the variable type and return string

<span>  gettype</span>(<span>$name</span>);

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>);

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>

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>

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

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>); // 输出数组内容

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

 Add array elements

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

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> 

9> Associative array

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

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>[键]

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>

 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>);

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"];

 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"];

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133563.htmlTechArticlePHP初体验,爱之初体验 1. 相关内容介绍 1互联网开发 互联网:传统互联网、移动互联网 互联网开发:前端开发(前台)、后台开发(后端、服...
Statement
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
How can you check if a PHP session has already started?How can you check if a PHP session has already started?Apr 30, 2025 am 12:20 AM

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Describe a scenario where using sessions is essential in a web application.Describe a scenario where using sessions is essential in a web application.Apr 30, 2025 am 12:16 AM

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

How can you manage concurrent session access in PHP?How can you manage concurrent session access in PHP?Apr 30, 2025 am 12:11 AM

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

What are the limitations of using PHP sessions?What are the limitations of using PHP sessions?Apr 30, 2025 am 12:04 AM

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

See all articles

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor