domdocument

PHP DOMDocument skips even elements

人盡茶涼 提交于 2019-12-24 09:40:16
问题 Hello I'm using this method to replace all iframe and img tags with span tags $string = clean($string); $dom = new \DOMDocument; $dom->loadHTML(mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $iframes = $dom->getElementsByTagName('iframe'); foreach($iframes as $iframe) { $src = $iframe->getAttribute('src'); $span = $dom->createElement('span'); $span->setAttribute('title', $src); $span->setAttribute('class', 'lazy-youtube'); $iframe-

Uncaught Error: Class 'Google\AdsApi\Examples\AdWords\v201809\Reporting\DOMDocument' not found

送分小仙女□ 提交于 2019-12-24 08:05:58
问题 I have php-xml installed and it runs fine with other php files using the following code to display xml on a web site: $doc = new DOMDocument(); $doc->loadXML(html_entity_decode($xml), LIBXML_NOXMLDECL); echo $doc->saveXML(); But it won't work in Google AdWords Report API. It obviously has something to do with the namespace Google\AdsApi\Examples\AdWords\v201809\Reporting; I am not familiar with PHP and wonder how to get this DOMDocument working inside the Reporting namespace. Thanks. 回答1: You

excluding URLs from path links?

喜欢而已 提交于 2019-12-24 07:23:02
问题 In the function below, I'd like to specify a list of domains to exclude from the results. What are some options? Array collection to exclude? class KeywordSearch { const GOOGLE_SEARCH_XPATH = "//a[@class='l']"; public $searchQuery; public $numResults ; public $sites; public $finalPlainText = ''; public $finalWordList = array(); public $finalKeywordList = array(); function __construct($query,$numres=7){ $this->searchQuery = $query; $this->numResults = $numres; $this->sites = array(); }

excluding URLs from path links?

徘徊边缘 提交于 2019-12-24 07:21:25
问题 In the function below, I'd like to specify a list of domains to exclude from the results. What are some options? Array collection to exclude? class KeywordSearch { const GOOGLE_SEARCH_XPATH = "//a[@class='l']"; public $searchQuery; public $numResults ; public $sites; public $finalPlainText = ''; public $finalWordList = array(); public $finalKeywordList = array(); function __construct($query,$numres=7){ $this->searchQuery = $query; $this->numResults = $numres; $this->sites = array(); }

How to remove attributes using PHP DOMDocument?

若如初见. 提交于 2019-12-24 04:58:13
问题 With this piece of XML: <my_xml> <entities> <image url="lalala.com/img.jpg" id="img1" /> <image url="trololo.com/img.jpg" id="img2" /> </entities> </my_xml> I have to get rid of all the attributes within the image tags. So, I've done this: <?php $article = <<<XML <my_xml> <entities> <image url="lalala.com/img.jpg" id="img1" /> <image url="trololo.com/img.jpg" id="img2" /> </entities> </my_xml> XML; $doc = new DOMDocument(); $doc->loadXML($article); $dom_article = $doc->documentElement;

How to reset DOM state to the initial state (when page was firstly received?)

好久不见. 提交于 2019-12-24 04:25:18
问题 I manipulated a webpage DOM via some js libraries which altered the behaviour of onMouseup onMousedown and onMousemove , among other things which I can't be sure of. Using a DOM inspector I could see that some of these changes are set as properties of the main "document" object. So, what I am trying to figure out is a way to store, when the page is loaded, the initial state of the "document" object (or probably store the entire DOM?) so that later I will be able to restore it. My naive

Check if domnodelist->item(x)->nodeValue == “nbsp;”

谁都会走 提交于 2019-12-24 02:33:08
问题 I have logged in to, and grabbed the return page using CURL , loaded it with DOMDocument and then queried it with DOMXPATH (to find 'table.essgrid tr'). (I am then also querying the result to find child 'td's and) with the results, results->item(2)->nodeValue is either a date or what echos in browser as   or . I need to check if it will be a non break space or actual text. Hopefully that makes some sense with the code below. $dom = new DOMDocument(); $dom->loadHTML($result); $xpath = new

PHP/DOMDocument: unset() does not release resources

蓝咒 提交于 2019-12-23 23:53:29
问题 I've got a variable $dom that contains an instance of PHP's DOMDocument. This variable is being set and unset within a loop. unset($dom) will not release memory, though: memory_get_usage(false) reports that only 700B of about 10MB got released. memory_get_usage(true) reports the exact same amount of memory usage before and after unset() . I tried the following: I checked that the reference count of $dom is exactly one immediately before the call to unset() : xdebug_debug_zval('dom') reports:

Why am I getting an array of SimpleXMLElement Objects here?

泄露秘密 提交于 2019-12-23 20:02:50
问题 I have some code that pulls HTML from an external source: $doc = new DOMDocument(); @$doc->loadHTML($html); $xml = @simplexml_import_dom($doc); // just to make xpath more simple $images = $xml->xpath('//img'); $sources = array(); Then, if I add all of the sources with this code: foreach ($images as $i) { array_push($sources, $i['src']); } echo "<pre>"; print_r($sources); die(); I get this result: Array ( [0] => SimpleXMLElement Object ( [0] => /images/someimage.gif ) [1] => SimpleXMLElement

PHP: documentElement->childNodes warning

你。 提交于 2019-12-23 19:28:33
问题 $xml = file_get_contents(example.com); $dom = new DomDocument(); $dom->loadXML($xml); $items = $dom->documentElement; foreach($items->childNodes as $item) { $childs = $item->childNodes; foreach($childs as $i) { echo $i->nodeValue . "<br />"; } } Now I get this warning in every 2nd foreach: Warning: Invalid argument supplied for foreach() in file_example.php on line 14 Please help guys. Thanks! 回答1: Some nodes don't have children, so you're passing a null (invalid) argument to the foreach