PHP basic tutorial 1 php language basics php0 basics php basic practice

WBOY
Release: 2016-07-29 08:49:16
Original
1228 people have browsed it

What is a PHP file?

PHP files can contain text, HTML, CSS and PHP code
The PHP code is executed on the server and the results are returned to the browser as plain text
The suffix of PHP files is “.php”


What can PHP do?

PHP can generate dynamic page content
PHP can create, open, read, write, delete and close files on the server
PHP can receive form data
PHP can send and retrieve cookies
PHP can add, delete, and modify data in the database
PHP can restrict users from accessing certain pages in the website
PHP can encrypt data
With PHP you are not limited to just outputting HTML. You can also export images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.


PHP supports three types of annotations:

<code><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>body</span>></span><span><span><?php</span><span>// 这是单行注释</span><span># 这也是单行注释</span><span>/*
这是多行注释块
它横跨了
多行
*/</span><span>?></span></span><span></<span>body</span>></span><span></<span>html</span>></span></code>
Copy after login

PHP Case Sensitive

In PHP, all user-defined functions, classes and keywords (such as if, else, echo, etc.) are not case sensitive.
In the following example, all three echo statements are legal (equivalent):
Example

<code><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>body</span>></span><span><span><?php</span><span>ECHO</span><span>"Hello World!<br>"</span>;
<span>echo</span><span>"Hello World!<br>"</span>;
<span>EcHo</span><span>"Hello World!<br>"</span>;
<span>?></span></span><span></<span>body</span>></span><span></<span>html</span>></span></code>
Copy after login

Hello World!
Hello World!
Hello World!


But in PHP, all variables are case-sensitive.
In the example below, only the first statement will display colorchange Amount of worth( This is Because is color, CO LOR to and coLOR are treated as three different variables):
Example

<code><span><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>body</span>></span><span><span><?php</span><span>$color</span>=<span>"red"</span>;
<span>echo</span><span>"My car is "</span> . <span>$color</span> . <span>"<br>"</span>;
<span>echo</span><span>"My house is "</span> . <span>$COLOR</span> . <span>"<br>"</span>;
<span>echo</span><span>"My boat is "</span> . <span>$coLOR</span> . <span>"<br>"</span>;
<span>?></span></span><span></<span>body</span>></span><span></<span>html</span>></span></span></code>
Copy after login

My car is red
My house is
My boat is


PHP 5 echo and print statements

PHP echo and print statements

The difference between echo and print:
echo - can output more than one string
print - can only output one string, and Always returns 1
Tip: echo is slightly faster than print because it doesn't return any value.

PHP echo statement
echo is a language construct that can be used with or without parentheses: echo or echo().

<code><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>body</span>></span><span><span><?php</span><span>echo</span><span>"<h2>PHP 很有趣!</h2>"</span>;
<span>echo</span><span>"Hello world!<br>"</span>;
<span>echo</span><span>"我计划学习 PHP!<br>"</span>;
<span>echo</span><span>"这段话"</span>, <span>"由"</span>, <span>"多个"</span>, <span>"字符串"</span>, <span>"串接而成。"</span>;
<span>$txt1</span>=<span>"Learn PHP"</span>;
<span>$txt2</span>=<span>"W3School.com.cn"</span>;
<span>$cars</span>=<span>array</span>(<span>"Volvo"</span>,<span>"BMW"</span>,<span>"SAAB"</span>);
<span>echo</span><span>$txt1</span>;
<span>echo</span><span>"<br>"</span>;
<span>echo</span><span>"Study PHP at $txt2"</span>;
<span>echo</span><span>"<br>"</span>;
<span>echo</span><span>"My car is a {$cars[0]}"</span>;

<span>?></span></span><span></<span>body</span>></span><span></<span>html</span>></span></code>
Copy after login

Hello world!
I plan to learn PHP!
This paragraph is composed of multiple strings concatenated.
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo

PHP print statement
Print is also a language construct and can be used with or without parentheses: print or print().

<code><span><span><!DOCTYPE html></span><span><<span>html</span>></span><span><<span>body</span>></span><span><span><?php</span><span>print</span><span>"<h2>PHP is fun!</h2>"</span>;
<span>print</span><span>"Hello world!<br>"</span>;
<span>print</span><span>"I'm about to learn PHP!"</span>;

<span>$txt1</span>=<span>"Learn PHP"</span>;
<span>$txt2</span>=<span>"W3School.com.cn"</span>;
<span>$cars</span>=<span>array</span>(<span>"Volvo"</span>,<span>"BMW"</span>,<span>"SAAB"</span>);
<span>print</span><span>$txt1</span>;
<span>print</span><span>"<br>"</span>;
<span>print</span><span>"Study PHP at $txt2"</span>;
<span>print</span><span>"<br>"</span>;
<span>print</span><span>"My car is a {$cars[0]}"</span><span>?></span></span><span></<span>body</span>></span><span></<span>html</span>></span></span></code>
Copy after login

PHP is fun!

Hello world!
I’m about to learn PHP!
Learn PHP
Study PHP at W3School.com.cn
My car is a Volvo

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above has introduced PHP basic tutorial 1, including PHP and basic aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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!