PHP bermaksud pemproses hiperteks yang direka bentuk sebagai bahasa skrip sebelah pelayan untuk membangunkan aplikasi web. Kod PHP terutamanya digabungkan atau dibenamkan dengan sintaks HTML, tetapi ia boleh digunakan untuk mana-mana sistem templat aplikasi web atau rangka kerja web yang tersedia.
Terdapat banyak arahan PHP yang tersedia untuk digunakan dalam pelbagai persekitaran, terutamanya untuk menyediakan satu aplikasi web atau membenamkan keseluruhan pangkalan kod sisi pelayan dengan sintaks HTML dan sangat mudah dipelajari untuk pembangun biasa. Beberapa arahan PHP asas disebut di bawah:
IKLAN Kursus Popular dalam kategori ini PEMBANGUN PHP - Pengkhususan | 8 Siri Kursus | 3 Ujian Olok-olokMulakan Kursus Pembangunan Perisian Percuma Anda
Pembangunan web, bahasa pengaturcaraan, ujian perisian & lain-lain
IF [SPECIFIC CONDITION]{ [CODE] }ELSE IF [SPECIFIC CONDITION 2]{ [CODE] }ELSE { [CODE] }
PHP juga menggunakan suis case, seperti bahasa pengaturcaraan lain untuk mengelakkan definisi bersarang bagi berbilang 'IF ELSE'. Tukar kes mempertimbangkan beberapa bilangan kes, dan menentukan lalai adalah pilihan. Struktur kod untuk menentukan sarung suis adalah seperti di bawah:
SWITCH($var){ CASE 'val 1' [CODE] Break; CASE 'val 2' [CODE] Break; CASE 'val 3' [CODE] Break; DEFAULT [CODE] }
WHILE [condition or expression]{ [CODE] }
For(exp 1, exp 2, exp 3){ [CODE] }
DO { [CODE] }WHILE (condition)
FOREACH ($arr_var as $val){ [CODE] }
Terdapat beberapa arahan PHP lain yang popular, yang juga digunakan oleh pembangun PHP, yang bukan perintah yang sangat asas tetapi lebih berfungsi dengan PHP. Beberapa jenis perintah PHP perantaraan yang disenaraikan di bawah:
In PHP, INCLUDE is mainly using for appending define code in an external file with the current working file.
INCLUDE ('name of the external file')
Maximum business logic can be defined within this PHP function.
Function "name of the function" (argument1, argument2 …){ [CODE] Return "expected result"; }
Array is mainly holding multiple related information in a single variable. Three kinds of arrays PHP normally supported.
It is similar to the HTML form.
<form action="" name="" type="post">
However, some of the critical tasks often need to be performed by the users of the PHP command. These tasks also have some advanced commands to execute, such as storing the cookie value, redirecting the page to some relevant pages or connecting to the database. Those advance kind of PHP commands are below:
A cookie is mainly using storing some of the user type value in their own system so that it can come automatically for the same website.
setCiookie(ckname, ckvalue, ckexpire, ckpath, ckdomain, cksecure) >>> creating Cookie $_COOKIE['cookie name'] >>> get cookies value
Redirecting to a new page by below command:
Header("Location:'URL to redirect'");
Some common users who are very frequently using PHP commands, they normally use some of the tips and tricks for utilizing PHP commands output in a proper way. Those kinds of tricks normally solving some user-specific queries and display execution output for understanding the same properly. Some of the very commonly used key tricks are:
For little critical complexity of business logic, sometimes developer using huge ‘IF-ELSE’ condition which creates a real problem of understanding the logic and final review. So one of the popular operators in PHP for avoiding the same is the Ternary operator. It is something like if conditions are true then doing something, else fetching some default value.
$value = (!empty($_GET['val'])? $_GET['val']: 'ABC');
Somehow requirement of using some common files in multiple pages, In that case rather than mention those common files in every page, a developer can make one common header and mention those common classes on that header page.
PHP is now a very popular programming language which used by the maximum common web application. If an organization are not a big concern with the site security or code vulnerability then PHP will be always a good option. The population of a page in PHP is very fast rather than any programming language.
Atas ialah kandungan terperinci Perintah PHP. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!