domdocument

How can i read the first XML comment in PHP?

送分小仙女□ 提交于 2020-01-07 02:16:30
问题 How can I read the first and only comment in PHP: <?xml version="1.0" encoding="UTF-8"?> <!-- read this --> <root> </root> using DOMDOcument object? $xml = new DOMDocument(); $libxml_error = 'Il file %s non risulta ben formato (%s).'; // Per evitare i warning nel caso di xml non ben formato occorre sopprimere // gli errori if (!@$xml -> load($xml_file_path)) $error = sprintf($libxml_error, $xml_file_path, libxml_get_last_error()->message); // Read the fist comment in xml file 回答1: What about

DOMDocument and delete parent tag

假装没事ソ 提交于 2020-01-05 12:35:15
问题 We load html by url. After that creating DOMDocument libxml_use_internal_errors(true); // disable errors $oHtml = new DOMDocument(); if (!$oHtml->loadHTML($this->getHtml($aData['href']))) { return false; } Next step is to delete fancybox or other popUp links... In our case image code is <a onclick="return hs.expand(this)" href="http://domain.com/uploads/09072014106.jpg"> <img title="Some title" alt="Some title" src="http://domain.com/uploads/thumbs/09072014106.jpg"> </a> And we execute our

Finding a line/string of text in HTML using DOM

一世执手 提交于 2020-01-05 09:15:28
问题 I have some Plain Text/HTML Content like so: Title: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Snippet: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Category: Lorem ipsum dolor sit amet, consectetur adipiscing elit. and i want to match only the line where it says " Snippet: and the text that follows it, BUT ONLY on that line, nothing else, and also making the search case-insensitive . I tried with regular expressions, but ultimately i want to attempt using

Finding a line/string of text in HTML using DOM

寵の児 提交于 2020-01-05 09:15:03
问题 I have some Plain Text/HTML Content like so: Title: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Snippet: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Category: Lorem ipsum dolor sit amet, consectetur adipiscing elit. and i want to match only the line where it says " Snippet: and the text that follows it, BUT ONLY on that line, nothing else, and also making the search case-insensitive . I tried with regular expressions, but ultimately i want to attempt using

How to Keep HTML Formatting Intact When Parsing with DOM - (No Tag Stripping)

喜你入骨 提交于 2020-01-05 08:17:52
问题 Employing DOMDocument, I'm trying to read a portion of an HTML file and displaying it on a different HTML page using the code below. The DIV portion that I'm trying to access has several <p> tags. The problem is when DOM parses the file, it only fetches the text content between the <p> tags - strips tags - and the paragraph formatting is lost. It merges the texts and displays them all as one paragraph. How can I keep the HTML formatting so that the paragraphs are displayed as they were in the

How to Keep HTML Formatting Intact When Parsing with DOM - (No Tag Stripping)

六眼飞鱼酱① 提交于 2020-01-05 08:17:48
问题 Employing DOMDocument, I'm trying to read a portion of an HTML file and displaying it on a different HTML page using the code below. The DIV portion that I'm trying to access has several <p> tags. The problem is when DOM parses the file, it only fetches the text content between the <p> tags - strips tags - and the paragraph formatting is lost. It merges the texts and displays them all as one paragraph. How can I keep the HTML formatting so that the paragraphs are displayed as they were in the

DOMDocument : how to get inner HTML as Strings separated by line-breaks?

巧了我就是萌 提交于 2020-01-05 03:37:30
问题 <blockquote> <p> 2 1/2 cups sweet cherries, pitted<br> 1 tablespoon cornstarch <br> 1/4 cup fine-grain natural cane sugar </p> </blockquote> hi , i want to get the text inside 'p' tag . you see there are three different line and i want to print them separately after adding some extra text with each line . here is my code block $tags = $dom->getElementsByTagName('blockquote'); foreach($tags as $tag) { $datas = $tag->getElementsByTagName('p'); foreach($datas as $data) { $line = $data->nodeValue

PHP DOMXPath query using the innerHTML/nodeValue of an element to find and return the element

好久不见. 提交于 2020-01-04 15:25:14
问题 Can you please help me with the correct syntax to use when you want to check the innerHTML/nodeValue of an element? I have no problem with the Name however the Age is within a plain div element, What is the correct syntax to use in place of "NOT SURE WHAT TO PUT HERE" below. $html is a page from the internet The persons name is in a span like: <span class="fullname">John Smith</span> The persons age is in a div like: <div>Age: 28</div> I have the following PHP: <?php $dom = new DomDocument();

PHP DomDocument : How remove a div?

别说谁变了你拦得住时间么 提交于 2020-01-04 15:13:31
问题 Here is my code : $doc = new DOMDocument(); $doc->loadHTML(stripslashes($sContent)); // si le meta existe alors il y a un sondage if($doc->getElementById('meta') != null){ $nombreMeta = $doc->getElementById('meta')->nodeValue; $numSondage = $doc->getElementById('meta')->getAttribute('class'); for($i=0;$i<$nombreMeta;$i++){ $meta = $meta."0,"; } $meta = substr($meta,0,-1); $divMeta = $doc->getElementById('meta'); $oldchapter = $doc->removeChild($divMeta); $oHead = $doc->getElementsByTagName(

PHP DOMDocument / XPath: Get HTML-text and surrounded tags

依然范特西╮ 提交于 2020-01-04 07:47:18
问题 I am looking for this functionality: Given is this html-Page: <body> <h1>Hello, <b>world!</b> </h1> </body> I want to get an array that only contains the DISTINCT text elements (no duplicates) and an array of the tags that surround the text elements: The result to the above "html" would be an array that looks like this: array => "Hello," surrounded by => "h1" and "body" "world!" surrounded by => "b", "h1" and "body" I alreday do this: $res=$xpath->query("//body//*/text()"); which gives me the