외부 URL에서 정보를 수집하고 그 값만 제거하려고합니다. 예를PHP Dom 파서가 스팬 값을 얻습니다.
<span id="ctl00_cphRoblox_rbxUserStatisticsPane_lFriendsStatistics">149</span>
를 들어
나는
도와주세요 '149'을 얻기 위해 PHP 돔을 사용하는 방법을 찾을 수 없습니다, 감사합니다!
외부 URL에서 정보를 수집하고 그 값만 제거하려고합니다. 예를PHP Dom 파서가 스팬 값을 얻습니다.
<span id="ctl00_cphRoblox_rbxUserStatisticsPane_lFriendsStatistics">149</span>
를 들어
나는
도와주세요 '149'을 얻기 위해 PHP 돔을 사용하는 방법을 찾을 수 없습니다, 감사합니다!
한 가지 방법은 주위 preg_match()
을 사용하는 것입니다,하지만 난 단지
$row = '<span id="ctl00_cphRoblox_rbxUserStatisticsPane_lFriendsStatistics">149</span>';
preg_match_all('/<span.*?>.*?<\/[\s]*span>/s', $row, $matches2);
var_dump($matches2);
또 다른 옵션은 simple_html_dom.php 사용하는 것입니다 ... 컬()와 함께 사용합니다 :
include('simple_html_dom.php');
$html = str_get_html($row);
var_dump($html->find('span', 0)->plaintext);
을
그리고 세 번째는 내장 된 DOMDocument를 사용하는 것입니다.
function DOMRemove(DOMNode $from) {
$sibling = $from->firstChild;
do {
$next = $sibling->nextSibling;
$from->parentNode->insertBefore($sibling, $from);
} while ($sibling = $next);
$from->parentNode->removeChild($from);
}
$dom = new DOMDocument;
$dom->load('test.html');
$nodes = $dom->getElementsByTagName('span');
foreach ($nodes as $node) {
DOMRemove($node);
}
echo $dom->saveHTML();
출처 : 또한 https://stackoverflow.com/a/4663865/1675369