domdocument

Convert date using strtotime from DOMDocument element

Hi there I'm parsing some data using DOMDocument after fetching HTML file using curl. The codes look like this $dom = new DOMDocument(); @$dom->loadHTML($content); $tables = $dom->getElementsByTagName('table'); $rows = $tables->item($tblNum)->getElementsByTagName('tr'); foreach ($rows as $row) { $cols = $row->getElementsByTagNam...

error when passing rss feed to php domDocument object

Hello, can anyone possibly point me in the right direction I am using curl to get back a google picasa api feed. This all works well, with the autorisation and the fetching of the data, but now I want to expand a little bit in try'n to add,update tags,pics, geo-info from my site. How can I pass the feed I got back with curl to the dom...

Removing inline elements when importing HTML into DOMDocument or SimpleXML?

I have an external HTML source that I want to scrape and either transform into a local XML file or add to a MySQL DB. The external source is mostly normalized and (somewhat) semantic, so that all I need to do is use XPATH to get all td content or all li content, etc. The problem is that occasionally these items use <strong> or <b> or <i...

error php domDocument xml parsing

Hi, Does anybody know how I can get this xml into the domDocument? Right now, it throws an error saying it is missing a top level element. What I see is that feed is the toplevel element, so it's a mystery to me. This only happens if I run it threw the domDocument and not when I echo it out directly. The xml validator also gives no err...

PHP: Find XML node and insert child

I have an xml document with the following structure: <?xml version="1.0" encoding="UTF-8"?> <items> <item> <id>1</id> <url>www.test.com</url> </item> <item> <id>2</id> <url>www.test2.com</url> </item> </items> I would like to be able to search for a node value, such as the value of 1 for the id field. Then, on...

Get rid of ASCII characters in the output of HTML parsed by DOMdocument

Let's say I have this code, adapted from Adam Backstrom's answer to a previous question: $term = 'example'; // word I need to replace $replacement = '<strong>example</strong>'; // this will replace the $term $d = new DOMDocument; @$d->loadHTML($body); // specifically, drupal's $node->content['body']['#value'] in hook_nodeapi when $op='...

PHP DOMDocument replace DOMElement child with HTML string

Using PHP I'm attempting to take an HTML string passed from a WYSIWYG editor and replace the children of an element inside of a preloaded HTML document with the new HTML. So far I'm loading the document identifying the element I want to change by ID but the process to convert an HTML to something that can be placed inside a DOMElement i...

Creating a DOMDocument from a DOMNode in PHP

I get an XML string from a certain source. I create a DOMDocument object and load the XML string into it (with DOMDocument::loadXML()). Then I navigate through the XML doc using various methods (e.g. DOMXPath), until I find the node (a DOMNode, of course) that I want. This node has a bunch of descendants, and I want to take that entire...

Fix malformed XML in PHP before processing using DOMDocument functions.

I'm needing to load an XML document into PHP that comes from an external source. The XML does not declare it's encoding and contains illegal characters like &. If I try to load the XML document directly in the browser I get errors like "An invalid character was found in text content" also when loading the file in PHP I get lots of warnin...

DOMDocument::loadXML vs. HTML Entities

I currently have a problem reading in XHTML as the XML parser doesn't recognise HTML character entities so: <?php $text = <<<EOF <?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"&gt; <head> <title>Entities are Causing Me Problems</title> </head> <body> <p>Copy...

DOMDocument->saveHTMLFile saving escaped text

I am trying to save a string of html into the nodeValue attribute of a DOMElement in PHP, but after I save the file with DOMDocument->saveHTMLFile the string of HTML is escaped and I can not figure out how to get the string not be saved as escaped text. Any ideas? ...

PHP DOMDocument, finding specific tags

I'm looking to find a specific attribute of a specific tag in an HTML document using PHP DOMDocument. Specifically, there is a div with a unique class set, and only a single span inside of it. I need to retrieve the style attribute of that span tag. Example: <div class="uniqueClass"><span style="text-align: center;" /></div> For th...

PHP: DomElement->getAttribute

How can I take all the attribute of an element? Like on my example below I can only get one at a time, I want to pull out all of the anchor tag's attribute. $dom = new DOMDocument(); @$dom->loadHTML(http://www.example.com); $a = $dom->getElementsByTagName("a"); echo $a->getAttribute('href'); thanks! ...

PHP DOMDocument - get html source of BODY

I'm using PHP's DOMDocument to parse and normalize user-submitted HTML using the loadHTML method to parse the content then getting a well-formed result via saveHTML: $dom= new DOMDocument(); $dom->loadHTML('<div><p>Hello World'); $well_formed= $dom->saveHTML(); echo($well_formed); This does a beautiful job of parsing the fragment and...

Get content from XML PHP5

Hi, I´m working on a paymentsolution and need some help with the PHP. I´m doing a HTTPRequest and in response I will get some XML. The XML Could look like this: <?xml version="1.0" encoding="utf-8" ?> <payer> <purchase_list> <freeform_purchase> <line_number>1</line_number> <description>d...

Parsing Malformed HTML with PHP Dom

I've got a client who wants their videos (provided by a third party) displayed on their web site. The web site uses swfobject to display the video, so I thought that it would be easiest to grab that and slightly modify it so that it works on the client's web site. Using PHP DOMDocument seems the way to go, but unfortunately the HTML tha...

Salesforce/PHP - outbound messages (SOAP) - memory limit issue? DOMDocument::loadXML() Premature end of data in tag issue?

UPDATE: OK I figured it out, looks like fread has a filesize limitation, changed this to file_get_contents('php://input') , but now having SF give a java.net.SocketTimeoutException: Read timed out error and nothing on the PHP side. I have also added set_time_limit(0); to the PHP script which if I understand correctly execute the scri...

html to text with domdocument class

How to get a html page source code without htl tags? For example: <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="content-language" content="hu"/> <title>this is the page title</title> <meta name="description" content="this is the description" /> <meta name="keywords" content="k1, k2, k3, k4" />...

WebKit & Objective-C: how to parse a HTML string into a DOMDocument?

How do you get a DOMDocument from a given HTML string using WebKit? In other words, what's the implementation for DOMDocumentFromHTML: for something like the following: NSString * htmlString = @"<html><body><p>Test</body></html>"; DOMDocument * document = [self DOMDocumentFromHTML: htmlString]; DOMNode * bodyNode = [[document getElemen...

PHP: documentElement->childNodes warning

$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 f...