Hi, I am timshaw9.

The basic grammar of the programming language “PHP” used for Web development, which is also the foundation of WordPress today, and their writing styles are summarized in a list.

In terms of content, if you have learned some programming language, this is an article for people who want to start PHP programming anew.

By the way, I’ve decided to put PHP on my own, so I would like to put it together and then go into the basic syntax summary of this subject.

What is PHP


PHP is a server-side scripting language that is used to create dynamic Web pages, especially on the server side. Also, its name is supposed to mean “PHP: Hypertext Preprocessor (= PHP is an HTML preprocessor)”.

The grammar is very similar to the affected C and Java.SOURCE: WIKIPEDIA- PHP (PROGRAMMING LANGUAGE)

A dynamic web page is, for example, a site where the latest articles are updated automatically. Since HTML alone can not build a system such as automatic updating, PHP generates HTML dynamically using PHP.

Imagewise, HTML is in charge of creating the basic structure of the web page (+ CSS is in charge of its decoration), and PHP programming controls it dynamically like a site created with WordPress. I think it is like myself.

Hypertext is a computer-based document creation and browsing system that associates and links multiple pieces of data. Also, the language for creating the hypertext is “HTML (Hypertext Markup Language)”.SOURCE: OTSUKA CHAMBER OF COMMERCE- IT GLOSSARY “HYPERTEXT”

Preprocessor is a program that preprocesses a program. If you compare in C language, this pre-processing (Preprocess) corresponds to “#include” (reading of external file) etc before compilation.

By the way, compilation is the process of converting source code written in a programming language into “native code (a machine language written with only binary 0s and 1s)” that the computer’s CPU can understand.SOURCE: E-WORDS- PREPROCESSOR

PHP and JavaScript differences

Like PHP, the scripting language used in web development is another well-known language, JavaScript.

The difference between the two is

  • PHP is a server-side language
  • JavaScript is a client-side language

is. Both are the same scripting language, but they work in different places.

As the name implies, server-side languages ​​run on “web servers”.

※ Web server: A place to store website data. When launching a blog site for an individual, you basically rent a web server.

So, as I mentioned earlier, PHP can be used to dynamically control data in the server, such as displaying the latest articles.

Also, like WordPress, when you write an article, HTML is automatically generated and a dynamic site is completed. Such applications can also be created using PHP.

Client-side language is a language that runs on a web browser.

※ Web browser: An application that receives HTML data of a web site from a web server and displays it in the form that we usually browse on the Internet. Main browser: Google Chrome, Safari, Fire Fox etc

※ Search engine: First, visit links to Web sites in servers around the world, and sort them by ranking them by category. And, based on the data, a system that displays the site that best matches the keyword entered by the user in the search window. Main search engine: Google, Yahoo, Bing etc

There are many sites where multiple images are flowing one by one like a slide show.

The processing performed on such a browser is performed by JavaScript.

Difference between script language and compilation language, difference between low level language and high level language

This has nothing to do with the content of this article, but I will summarize it for my own learning. .

As for the difference between the script language and the compilation language, I would like to link it, as Samurai Blog’s article “Does not require expert knowledge! What is a script language? Explain the language type and recommendations” is very easy to understand.

Put simply

  • Scripting language : No compilation required, code easy to write, often easy to read On the other hand, it is not suitable for large-scale projects because it omits data type declarations. In addition, the execution speed is slow and there are many that the usage is limited. Primary languages: Python, Ruby, JavaScript, PHP etc.
  • Compiling language : Compiling is always required before execution, and the code is a little more complicated than scripting language. However, it is fast, versatile, and suitable for large projects. Primary languages: Java, C, etc.

It’s like that.

With regard to the difference between low-level languages ​​and high-level languages, Nikkei XTECH’s “[Basic IT foundation to remember in 5 minutes] Let’s learn the assembler once by anyone!” I will leave.

A high-level language is a language that human beings speak, and can give instructions to a computer, and this is a common programming language currently used.

On the other hand, low-level languages ​​are languages ​​that humans can not understand, such as “Native code (machine language written with only binary 0 and 1)” mentioned a little earlier. However, a language called “assembly language” that makes machine language understandable to humans also falls within the framework of low-level languages.

Well, in this assembly language, a string representing a specific process in machine language is converted into one word for each string, and it is matched with the native code in a one-to-one sequence, It is a language that gives instructions.

So the form of the code itself does not change, but it is a notation that human beings can understand.

Basically, low-level languages ​​are longer in code length than high-level languages, and instructions are written in detail.

PHP basic syntax list

Basic rules

  • As in the C language, type a semicolon (;) for each line
  • File extension is (.php)
  • There are two ways to write single line comments: (// comment) and (# comment)
  • Write a multi-line comment (/ * comment * /)
  • The escape sequence is (\ character) ※ In the case of windows, it is a \ symbol.

How to write PHP in HTML code

If the processing content is a single line or if it is the final line, there is no obligation to add a semicolon

 <?php 処理内容; ?> 
 <?php処理内容1;処理内容2; ?> 

Display output

 print("Hello World!"); 

Variable definition

 $numSample = 0; $strSample = "Apple"; 
  • Be sure to put ($) at the beginning of the variable name
  • Alphabet, number, underscore (_) available
  • Case sensitive
  • Number can not be used for the first character of variable name
  • Indicate with the basic lower camel case (lowerCamelCase)

Character type literal

  • In the case of double quotes (“), replace variables in the string with variable values
 $doubleQuote = "timshaw9"; // This is timshaw9. print("This is $doubleQuote."); 

  • In single quote (‘), do not replace variables in string with variable values
 $singleQuote = 'timshaw9'; // This is $singleQuote. print("This is $singleQuote."); 

if statement

 /*等しい: ==等しくない: !=未満: <超える: >以下: <=以上: >= */ if(条件式) {処理内容1;処理内容2; } elseif(条件式) {処理内容1;処理内容2; } else {処理内容1;処理内容2; } # 処理内容が短文の場合は波括弧省略可if(条件式)処理内容; 

switch statement

 switch(比較対象) { case 条件1:処理内容; break; case 条件2:処理内容; break; case 条件3:処理内容; break; default:処理内容; break; } 

while statement

 /*累乗: **余りの計算: %元の値を代入してから1を加算: 変数++ 1を加算してから元の値を代入: ++変数 元の値を代入してから1を減算: 変数-- 1を減算してから元の値を代入: --変数*/ while(条件式) {処理内容; } 

for statement

 for(ループ開始前の処理; 条件式; 各ループの末端で行う処理) { if(条件式) continue;処理内容; } 

Array (dictionary)

 # PHPでは、辞書の中に配列の概念が含まれています。 // 辞書$dictSample[0] = "1"; $dictSample["1"] = 2; $dictSample = [ 0 => "1", "1" => 2, ]; // 配列$arraySample = [1, 2, 3]; 


If there is additional basic syntax, we will update it as needed.

I hope this article will help you learn PHP. .


Leave a Reply