Làm cách nào để lấy đầu ra HTML trong biến PHP?

Một mảng kết hợp gồm các biến được chuyển đến tập lệnh hiện tại thông qua phương thức HTTP POST khi sử dụng application/x-www-form-urlencoded hoặc multipart/form-data làm Loại nội dung HTTP trong yêu cầu

ví dụ

Ví dụ #1 $_POST ví dụ

echo 'Hello ' . htmlspecialchars[$_POST["name"]] . '!';
?>

Giả sử người dùng đã đăng tên=Hannes

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như

ghi chú

Ghi chú

Đây là biến 'siêu toàn cầu' hoặc toàn cầu tự động. Điều này đơn giản có nghĩa là nó có sẵn trong tất cả các phạm vi trong toàn bộ tập lệnh. Không cần phải làm $variable toàn cầu;

This post is with regards to handling forms that have more than one submit button.

Suppose we have an HTML form with a submit button specified like this:

Normally the 'value' attribute of the HTML 'input' tag [in this case "Delete"] that creates the submit button can be accessed in PHP after post like this:

________số 8_______

We of course use the 'name' of the button as an index into the $_POST array.

This works fine, except when we want to pass more information with the click of this particular button.

Imagine a scenario where you're dealing with user management in some administrative interface.  You are presented with a list of user names queried from a database and wish to add a "Delete" and "Modify" button next to each of the names in the list.  Naturally the 'value' of our buttons in the HTML form that we want to display will be "Delete" and "Modify" since that's what we want to appear on the buttons' faceplates.

Both buttons [Modify and Delete] will be named "action_button" since that's what we want to index the $_POST array with.  In other words, the 'name' of the buttons along cannot carry any uniquely identifying information if we want to process them systematically after submit. Since these buttons will exist for every user in the list, we need some further way to distinguish them, so that we know for which user one of the buttons has been pressed.

Using arrays is the way to go.  Assuming that we know the unique numerical identifier of each user, such as their primary key from the database, and we DON'T wish to protect that number from the public, we can make the 'action_button' into an array and use the user's unique numerical identifier as a key in this array.

Suppose we have an HTML form with a submit button specified like this:0

Suppose we have an HTML form with a submit button specified like this:1

Suppose we have an HTML form with a submit button specified like this:2

Suppose we have an HTML form with a submit button specified like this:3

Suppose we have an HTML form with a submit button specified like this:4

Suppose we have an HTML form with a submit button specified like this:5

Suppose we have an HTML form with a submit button specified like this:6

Suppose we have an HTML form with a submit button specified like this:7

Khi tạo một ứng dụng web bằng PHP, chúng ta thường cần in hoặc lặp lại một số kết quả dưới dạng HTML. Chúng ta có thể thực hiện nhiệm vụ này theo nhiều cách khác nhau. Một số phương pháp được mô tả ở đây

  1. Sử dụng tiếng vang hoặc in. PHP echo hoặc print có thể được sử dụng để hiển thị đánh dấu HTML, javascript, văn bản hoặc các biến

    ví dụ 1. Ví dụ này sử dụng PHP echo để hiển thị kết quả




Chủ Đề