Welcome Guest, Not a member yet? Register   Sign In
How do you parse a file and pull a block of markup?
#11

[eluser]Yorick Peterse[/eluser]
[quote author="nubianxp" date="1241481200"]@yorick: thanks for the code man, nice to have something to start with... one question, is it possible to maybe parse a remote file? e.g.
Code:
$remote = 'http://example.com/data.html';
$DOM = new DOMDocument();
$DOM->load($remote);
$content = $DOM->getElementById('somediv');
and do either
Code:
echo $content; OR
print_r($content);

i tested the above, but i get some parsing errors when using $dom->load():
Code:
Warning: DOMDocument::loadHTMLFile() [domdocument.loadhtmlfile]: error parsing attribute name in http://example.com/forecast.html, line: 19 in E:\localweb\projects\test\getfile.php on line 5

and a blank page if i use $dom->loadHTML()... anyway, appreciate the help. :lol:

@dam1an: 5,344?! and all of those are built-in?! :wow:[/quote]

I'm not really sure if you can parse a remote file using the DOM. However you could use file_get_contents() to fetch whatever is in that file and then parse it later on.

It would look like the following:

Code:
<?php
// Get the content from the remote file
$remote = file_get_contents('your_remote_file.html');

// Load the DOM
$DOM = new DOMDocument();

// Open the $remote variable using the DOM, not sure if it's possible
$DOM->load($remote);

// Parse it
.......


Messages In This Thread
How do you parse a file and pull a block of markup? - by El Forum - 05-03-2009, 06:26 PM
How do you parse a file and pull a block of markup? - by El Forum - 05-03-2009, 06:44 PM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 01:31 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 04:45 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 04:47 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 04:57 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 05:03 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 05:04 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 12:53 PM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 12:59 PM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 03:13 PM
How do you parse a file and pull a block of markup? - by El Forum - 05-04-2009, 07:19 PM
How do you parse a file and pull a block of markup? - by El Forum - 05-27-2009, 09:38 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-27-2009, 09:57 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-27-2009, 10:01 AM
How do you parse a file and pull a block of markup? - by El Forum - 05-27-2009, 10:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB