A
Anonymous
Guest
Dears,
how to html value export in xml file with tag in php. This code read all div value from site:
<?php
$some_link = 'http://www.popusti.rs/';
$tagName = 'div';
$attrName = 'class';
$attrValue = 'offer-list-item';
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($some_link);
$html = getTags( $dom, $tagName, $attrName, $attrValue );
echo $html;
function getTags( $dom, $tagName, $attrName, $attrValue ){
$html = '';
$domxpath = new DOMXPath($dom);
$newDom = new DOMDocument;
$newDom->formatOutput = true;
$filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
$filtered = $domxpath->query('//div[@class="offer-list-item"]');
// '//' when you don't know 'absolute' path
// since above returns DomNodeList Object
// I use following routine to convert it to string(html); copied it from someone's post in this site. Thank you.
$i = 0;
while( $myItem = $filtered->item($i++) ){
$node = $newDom->importNode( $myItem, true ); // import node
$newDom->appendChild($node); // append node
}
$html = $newDom->savehtml();
return $html;
}
?>
how to html value export in xml file with tag in php. This code read all div value from site:
<?php
$some_link = 'http://www.popusti.rs/';
$tagName = 'div';
$attrName = 'class';
$attrValue = 'offer-list-item';
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($some_link);
$html = getTags( $dom, $tagName, $attrName, $attrValue );
echo $html;
function getTags( $dom, $tagName, $attrName, $attrValue ){
$html = '';
$domxpath = new DOMXPath($dom);
$newDom = new DOMDocument;
$newDom->formatOutput = true;
$filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
$filtered = $domxpath->query('//div[@class="offer-list-item"]');
// '//' when you don't know 'absolute' path
// since above returns DomNodeList Object
// I use following routine to convert it to string(html); copied it from someone's post in this site. Thank you.
$i = 0;
while( $myItem = $filtered->item($i++) ){
$node = $newDom->importNode( $myItem, true ); // import node
$newDom->appendChild($node); // append node
}
$html = $newDom->savehtml();
return $html;
}
?>