Hướng dẫn how to set attribute in php? - làm thế nào để thiết lập thuộc tính trong php?

(Php 5, Php 7, Php 8)

Domelement :: SetAttribute - Thêm mới hoặc sửa đổi thuộc tính hiện cóAdds new or modifies existing attribute

Sự mô tả

Public Kmousement :: SetAttribut DOMElement::setAttribute(string $qualifiedName, string $value): DOMAttr|bool

Thông số

qualifiedName

Tên của thuộc tính.

value

Giá trị của thuộc tính.

Trả về giá trị

DOMATTR hoặc false được tạo hoặc sửa đổi nếu xảy ra lỗi.DOMAttr or false if an error occurred.

Errors/Exceptions

DOM_NO_MODIFICATION_ALLOWED_ERR

Lớn lên nếu nút được đọc lại.

Ví dụ

Ví dụ #1 Cài đặt thuộc tính

$doc = new DOMDocument("1.0");
$node $doc->createElement("para");
$newnode $doc->appendChild($node);
$newnode->setAttribute("align""left");
?>

Xem thêm

  • Domelement :: HasAttribut () - Kiểm tra xem thuộc tính có tồn tại
  • Domelement :: getAttribut () - Trả về giá trị của thuộc tính
  • Domelement :: removeAttribut () - Xóa thuộc tính

Rakesh Verma - Rakeshnsony tại Gmail Dot Com ¶

11 năm trước

//Store your html into $html variable.
$html="


Untitled Document


    Example

    Google

        Yahoo

$value0

$value1

Thông tin tại Ensostudio Dot Ru ¶

10 tháng trước

$value2

$value3

$value4

Địa chỉ tại Gmail Dot Com ¶

14 năm trước

$value5

$value6

$value7

lehal2@hotmail ¶

9 năm trước

$value8

$value9

qualifiedName0

Vasil Rangelov ¶

15 năm trước

qualifiedName1

qualifiedName2

qualifiedName3

qualifiedName4

$value7

Làm thế nào để bạn đặt các thuộc tính?

Phần tử.setAttribution () Đặt giá trị của một thuộc tính trên phần tử được chỉ định.Nếu thuộc tính đã tồn tại, giá trị được cập nhật;Mặt khác, một thuộc tính mới được thêm vào với tên và giá trị được chỉ định.Để có được giá trị hiện tại của một thuộc tính, hãy sử dụng getAttribution ();Để xóa một thuộc tính, hãy gọi RemoveAtribution (). Sets the value of an attribute on the specified element. If the attribute already exists, the value is updated; otherwise a new attribute is added with the specified name and value. To get the current value of an attribute, use getAttribute() ; to remove an attribute, call removeAttribute() .

Làm thế nào để thêm thuộc tính vào phần tử HTML trong PHP?

Bạn có thể dễ dàng thêm thuộc tính vào thẻ HTML bằng Regex và PHP.Hàm preg_replace () tìm kiếm chuỗi khớp với mẫu (biểu thức chính quy) và thay thế bằng thay thế.Sử dụng hàm preg_replace () với biểu thức thông thường để thêm thuộc tính vào thẻ HTML bằng PHP.using Regex and PHP. The preg_replace() function searches string matches to the pattern (regular expression) and replaces with replacement. Use preg_replace() function with regular expression to add attribute to HTML tag using PHP.