domdocument

PHP DOM: Get NodeValue excluding the child nodes

China☆狼群 提交于 2020-02-05 04:19:24
问题 I have a variable $content containing a piece of HTML code : <b>AMZN 466.00 ( 15743 ) ( <span class='red'> -1 </span>) MSFT 290.00 ( 37296 ) ( <span class='red'> -2 </span>) TWTR 4,000.00 ( 20 ) ( <span class=''> 0 </span>)</b> Now, I want the values of <b> excluding the values of <span> using PHP DOM. How can this be done? A code snippet would be helpful. So far, I've tried this: $dom = new domDocument; @$dom->loadHTML($content); $contents_i_want = $dom->getElementsByTagName('b'); foreach(

DOMDocument remove script tags from HTML source

时光总嘲笑我的痴心妄想 提交于 2020-02-01 14:36:28
问题 I used @Alex's approach here to remove script tags from a HTML document using the built in DOMDocument. The problem is if I have a script tag with Javascript content and then another script tag that links to an external Javascript source file, not all script tags are removed from the HTML. $result = ' <!doctype html> <html> <head> <meta charset="utf-8"> <title> hey </title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script>

DOMDocument remove script tags from HTML source

吃可爱长大的小学妹 提交于 2020-02-01 14:35:29
问题 I used @Alex's approach here to remove script tags from a HTML document using the built in DOMDocument. The problem is if I have a script tag with Javascript content and then another script tag that links to an external Javascript source file, not all script tags are removed from the HTML. $result = ' <!doctype html> <html> <head> <meta charset="utf-8"> <title> hey </title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script>

PHP XPath. How to return string with html tags?

假如想象 提交于 2020-01-24 15:59:45
问题 <?php libxml_use_internal_errors(true); $html = ' <html> <body> <div> Message <b>bold</b>, <s>strike</s> </div> <div> <span class="how"> <a href="link" title="text">Link</a>, <b> BOLD </b> </span> </div> </body> </html> '; $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->strictErrorChecking = false; $dom->recover = true; $dom->loadHTML($html); $xpath = new DOMXPath($dom); $messages = $xpath->query("//div"); foreach($messages as $message) { echo $message->nodeValue; } This

How to add DOCTYPE in export xml?

喜你入骨 提交于 2020-01-21 11:26:49
问题 I exported a xml file in PHP using: $xmldoc = new DOMDocument(); $xmldoc->formatOutput = true; $xmldoc->encoding="Shift_JIS"; // create root nodes $root = $xmldoc->createElement("TableData"); $xmldoc->appendChild( $root ); $xmldoc->save($filename); Result: <?xml version="1.0" encoding="Shift_JIS"?> <TableData> </TableData> Now, i want to add row <!DOCTYPE TableDef SYSTEM "TableData.dtd"> like: <?xml version="1.0" encoding="Shift_JIS"?> <!DOCTYPE TableDef SYSTEM "TableData.dtd"> <TableData> <

Export XML from form data [closed]

南楼画角 提交于 2020-01-17 13:53:30
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm trying to come up with a general routine for exporting form data to an XML format. The goal would be to make it general enough that the form element IDs would serve as the XML nodes, and the form values would obviously be the node content. Here's what I have so far: if(isset($_POST['submit'])) { $doc = new

How do i make Xpath 1.0 query case insensitive

无人久伴 提交于 2020-01-17 11:15:47
问题 In PHP, I'm currently making a xpath query but I need to make it case insensitive. I'm using is XPath 1.0 which from my query means I've got to use some thing called a translate function but I'm unsure of how to do this. Here is my query test PHP file : $html = <<<'HTML' <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"> <meta NAME="Description" content="Test Case"> <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"> <Link Rel="Canonical" href="http://www.testsite

How do I get the title and complete class value?

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-17 03:50:21
问题 I have two queries 1) <div class="a b" title="my title"> How do I get the title and complete class value ? ('a' always be a fixed class but not 'b'. Second class can be anything and also possiblity to have more than two classes.) 2) <h1><a link="dynamic_link" class="fix-class">my content< /a>< /h1> Get all attributes(link,class..) of 'a href' tag which belongs to only 'h1' tag Please help me out because I stuck on this point from last two days and not able to get any solution from google.

print html table using php dom document

て烟熏妆下的殇ゞ 提交于 2020-01-17 01:20:52
问题 Need help, I would like to print this html code in our web page using php domdocument, but struggling I have also write the code with below. Could you please help me. <table width="610" id="machine" border="0" cellSpacing="10" cellPadding="0"> <TBODY> <TR> <TD colSpan=2 align=left> <DIV id=breadcrumbs><A href="/new-and-used-machinery.php">All Machines</A>  >  <A href="/listing.php?cat=Air+Compressors">Air Compressors</A>  > </DIV> <DIV id=ForSale>FOR SALE:</DIV> <H1>5 CFM Used Speedaire Air

Loading RSS file with DOMDocument

僤鯓⒐⒋嵵緔 提交于 2020-01-16 18:40:14
问题 I'm having an issue with my PHP assignment for school. I have to create a PHP script that reads an XML file with bunch of URLs to different RSS feeds. I'm using DOMDocument to retrieve an URL from this XML file and load a new DOM with the RSS feed. I assign the "url" node value to $url and then create a new DOM object for the RSS feed using $url. $url = $student->getElementsByTagName("url"); $url = $url->item(0)->nodeValue; $rss = new DOMDocument(); $rss->load($url); The RSS file will not