phpQuery 문법
페이지 정보
작성자 서방님 댓글 0건 조회 71회 작성일 20-07-09 17:15본문
<? $document = phpQuery::newDocumentHTML("HTML markup"); $container = pq("#container"); // Operates on the document loaded above // Explicitly specifies which document to query $secondDocument = phpQuery::newDocumentXHTML("HTML markup"); $container = pq("#container", $secondDocument); // Queries the document with a specific ID $thirdDocument = phpQuery::newDocumentXHTML("HTML markup"); $container = pq("#container", $thirdDocument->getDocumentID()); // Invoking the find method on a document corresponds to the pq method $container = $thirdDocument->find("#container"); /********************************************************************************/ $document = phpQuery::newDocumentHTML("HTML markup"); // Selects all elements with a given class $matches = $document->find(".some-class"); // Selects the element with a given ID $match = $document->find("#some-id"); // Selects all input elements $matches = $document->find(":input"); // Selects all text input elements $matches = $document->find(":input[type=text]"); /* Selects input elements that have a "data-city" attribute with a value of "New York" */ $matches = $document->find("input[data-city="New York"]"); // Matches the first child of each table row $matches = $document->find("tr:first-child"); /********************************************************************************/ $document = phpQuery::newDocumentHTML("HTML markup"); // Gets the element"s value for the "class" attribute $class = $document->find("#container")->attr("class"); // Sets the element"s "class" attribute $document->find("#container")->attr("class", "my-container"); // Removes the "class" attribute $document->find("#container")->removeAttr("class"); // Adds "my-container" to the element"s "class" attribute $document->find("#container")->addClass("my-container"); // Removes "my-container" from the element"s "class" attribute $document->find("#container")->removeClass("my-container"); // Gets the HTML content of the element $html = $document->find("#container")->html(); // Sets the HTML content of the element $document->find("#container")->html("HTML markup"); // Gets the text content of the element // This function is similar to PHP"s strip_tags function $text = $document->find("#container")->text(); // Sets the element"s text $document->find("#container")->text("some text"); // Append content to an element $document->find("#container")->append("some content"); // Prepend content to an element $document->find("#container")->prepend("some content"); // Gets the value of the "value" attribute $username = $document->find("#username-textbox")->val(); // Sets the value of the "value" attribute $document->find("#username-textbox")->val("some value"); // Removes all child nodes $document->find("#container")->empty(); ?>
댓글목록
등록된 댓글이 없습니다.