Cấu trúc xác định ngôn ngữ máy tính PHP được gọi là cú pháp PHP.PHP syntax.
Tập lệnh PHP được thực thi trên máy chủ và kết quả HTML được gửi đến trình duyệt. Nó thường có thể có thẻ HTML và PHP. PHP hoặc Supertext ProMessor là một ngôn ngữ tập lệnh đa năng nguồn mở được sử dụng rộng rãi và có thể được nhúng với HTML. Các tệp PHP được lưu với tiện ích mở rộng. Các tập lệnh PHP có thể được viết ở bất cứ đâu trong tài liệu trong các thẻ PHP cùng với HTML. & NBSP; & NBSP bình thường;
Thoát khỏi PHP:
Viết mã PHP bên trong được gọi là Escaping thành PHP. Escaping to PHP.
Cơ chế tách HTML bình thường khỏi mã PHP được gọi là cơ chế thoát khỏi PHP. Có nhiều cách khác nhau trong đó điều này có thể được thực hiện. Một số phương pháp đã được đặt theo mặc định nhưng để sử dụng một số phương pháp khác như thẻ ngắn hoặc thẻ kiểu ASP, chúng ta cần thay đổi cấu hình của tệp PHP.INI. Các thẻ này cũng được sử dụng để nhúng PHP trong HTML. Có 4 thẻ như vậy có sẵn cho mục đích này.
Thẻ PHP chính tắc: Kịch bản bắt đầu bằng. Các thẻ này còn được gọi là ‘thẻ Php chính tắc. Tất cả mọi thứ bên ngoài một cặp thẻ mở và đóng đều bị bỏ qua bởi trình phân tích cú pháp PHP. Các thẻ mở và đóng được gọi là Delimiter. Mỗi lệnh PHP kết thúc bằng một đại hội (;). Hãy cùng xem chương trình Hello World trong PHP. & NBSP; & nbsp;: The script starts with . These tags are also called ‘Canonical PHP tags’. Everything outside of a pair of opening and closing tags is ignored by the PHP parser. The open and closing tags are called delimiters. Every PHP command ends with a semi-colon (;). Let’s look at the hello world program
in PHP.
PHP
<?php
Hello, world!0____11 Hello, world!2Hello, world!3
Hello, world!1 Hello, world!5Hello, world!6
Hello, world!7
Output:
Hello, world!Thẻ SGML hoặc HTML ngắn: Đây là tùy chọn ngắn nhất để khởi tạo mã PHP. Kịch bản bắt đầu với. Điều này sẽ chỉ hoạt động bằng cách cài đặt cài đặt Short_open_tag trong tệp php.ini thành ‘trên. & NBSP; & nbsp;: These are the shortest option to initialize a PHP code. The script starts with . This will only work by setting the short_open_tag setting in the php.ini file to ‘on’.
Example:
PHP
Hello, world!8
Hello, world!0____11 Hello, world!2Hello, world!3
Hello, world!1 Hello, world!5Hello, world!6
Hello, world!1 Hello, world!5Hello, world!6
Hello, world!7
Output:
Hello, world!Thẻ SGML hoặc HTML ngắn: Đây là tùy chọn ngắn nhất để khởi tạo mã PHP. Kịch bản bắt đầu với. Điều này sẽ chỉ hoạt động bằng cách cài đặt cài đặt Short_open_tag trong tệp php.ini thành ‘trên. & NBSP; & nbsp;: These are implemented using script tags. This syntax is removed in PHP 7.0.0. So its no more used.
Hello, world!0____11 hello world!1hello world!2
PHP
hello world0hello world1hello world2
Hello, world!0____11 Hello, world!2Hello, world!3
hello world6
Output:Output:
hello world!Hello, world!1 Hello, world!5Hello, world!6: To use this we need to set the configuration of the php.ini file. These are used by Active Server Pages to describe code blocks. These tags start with .
Example:
PHP
hello world7
Hello, world!0____11 Hello, world!2Hello, world!3
hello world!!!1
Hello, world!1 Hello, world!5Hello, world!6
hello world!!!5
Output:
hello worldConstants:
Thẻ SGML hoặc HTML ngắn: Đây là tùy chọn ngắn nhất để khởi tạo mã PHP. Kịch bản bắt đầu với. Điều này sẽ chỉ hoạt động bằng cách cài đặt cài đặt Short_open_tag trong tệp php.ini thành ‘trên. & NBSP; & nbsp;
Hello, world!0____11 hello world!1hello world!2
- hello world!3hello world!4 hello world!5
- Thẻ tập lệnh HTML: Chúng được triển khai bằng cách sử dụng thẻ script. Cú pháp này được xóa trong Php 7.0.0. & nbsp; vì vậy nó không được sử dụng nữa. & nbsp; & nbsp;
Ví dụ: & nbsp; & nbsp;
Hello, world!1 hello world4Hello, world!6
Thẻ kiểu ASP: Để sử dụng điều này, chúng ta cần đặt cấu hình của tệp php.ini. Chúng được sử dụng bởi các trang máy chủ hoạt động để mô tả các khối mã. Các thẻ này bắt đầu bằng. & NBSP;
PHP supports two types of comment:
- hello world8hello world!2 hello world!!!0: As the name suggests these are single line or short relevant explanations that one can add to their code. To add this, we need to begin the line with (//) or (#).
Example:
PHP
<?php
Hello, world!0____11 Hello, world!2Hello, world!3
hello world!0
Hello, world!7
Output:
- Hello, world!1 Hello, world!5Hello, world!6: These are used to accommodate multiple lines with a single tag and can be extended to many lines as required by the user. To add this, we need to begin and end the line
with (/*…*/)
PHP
<?php
Hello, world!0____11 Hello, world!2Hello, world!3
Hello, world!1 Hello, world!5Hello, world!6
Hello, world!7
Output:
hello world!Thẻ SGML hoặc HTML ngắn: Đây là tùy chọn ngắn nhất để khởi tạo mã PHP. Kịch bản bắt đầu với. Điều này sẽ chỉ hoạt động bằng cách cài đặt cài đặt Short_open_tag trong tệp php.ini thành ‘trên. & NBSP; & nbsp;
- Hello, world!0____11 hello world!1hello world!2 This includes all types of spaces that are invisible on the screen including tabs, spaces, and carriage returns. Even one space is equal to any number of spaces or carriage returns. This means that PHP will ignore all the spaces or tabs in a single row or carriage return in multiple rows. Unless a semi-colon is encountered, PHP treats multiple lines as a single command.
Example:
PHP
<?php
Hello, world!0____11 Hello, world!2Hello, world!3
Hello, world!1 Hello, world!5Hello, world!6
45 456
Thẻ SGML hoặc HTML ngắn: Đây là tùy chọn ngắn nhất để khởi tạo mã PHP. Kịch bản bắt đầu với. Điều này sẽ chỉ hoạt động bằng cách cài đặt cài đặt Short_open_tag trong tệp php.ini thành ‘trên. & NBSP; & nbsp;
25 25 250
45 454Hello, world!6
Hello, world!0____11 hello world!1hello world!2
25 25 258 hello world!445 452 Positive as greater than 0145 454Hello, world!6
Hello, world!1 25 25 258Hello, world!6
Hello, world!7
Output:
45 45Cả hai đều cho thấy kết quả giống nhau mà không có bất kỳ lỗi nào.
- PHP nhạy cảm trường hợp. Tất cả các từ khóa, chức năng và tên lớp trong PHP (trong khi, nếu, echo, khác, v.v.) không nhạy cảm với trường hợp ngoại trừ các biến. Chỉ các biến với các trường hợp khác nhau được đối xử khác nhau. Hãy cùng xem xét ví dụ này: & nbsp; & nbsp;. All the keywords, functions, and class names in PHP (while, if, echo, else, etc) are NOT case-sensitive except variables. Only variables with
different cases are treated differently. Let’s look at this example:
PHP
<?php
Positive as greater than 09 <?php0
Hello, world!1 Positive as greater than 09Hello, world!6
<?php4 Positive as greater than 09Hello, world!6
<?php7 Positive as greater than 09Hello, world!6
Hello, world!1 Hello, world!01
Hello, world!7
Output:
Khối trong PHP:
Trong PHP, nhiều câu lệnh có thể được thực thi đồng thời (trong một điều kiện hoặc vòng lặp) bằng cách sử dụng t-t-braces ({}). Điều này tạo thành một khối các câu lệnh được thực thi đồng thời. & Nbsp; & nbsp;{}). This forms a block of statements that gets executed simultaneously.
PHP
<?php
Positive as greater than 09 <?php0
Hello, world!1 Positive as greater than 09Hello, world!6
<?php4 Positive as greater than 09Hello, world!6
<?php7 Positive as greater than 09Hello, world!6
Hello, world!20
Hello, world!7
Output: tput:
Hello, world!1 Hello, world!01Chinmoy Lenka. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic
discussed above.