What class are you using for the $html->find? Not sure how this method is supposed to work. What does find return? What are the allowed parameters? In what format are the parameters?
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
You tested with what ? This one ?
$html->find('$html->find('#divid');');
$html->find('div[id=divid]');
Does it correct use ? In my opinion, your class wont' work while it is quoting, the first line. Furthermore, why the class is inside the same class as parameter.
Perhaps, you would not probably well read the instruction. I don't know what that snippet would suppose which function.
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
Perhaps try:
$html->find('#divid');
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Yes, but looking at the source, that's just a wrapper of:
$html->find('#div1', 0);
Where the 0 makes it return the first one (I think, which seems useless to me, but they also included a getElementsById function, which returns all elements with the ID. Go figure).
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101
Give XPath a try, here is a sample I have in my personal library:
txt-file.txt
<?xml version="1.0"?>
<body>
This line of information will be pulled because it is in between the body tags!
</body>
And the PHP Code:
<?php
$filename = "txt-file.txt"; // xml formatted text file...
// open the file and load contents into $string
$fh = fopen($filename, "r") or die("Can't open file");
$string = fread($fh, filesize($filename));
fclose($fh);
// Get it ready for XPath
$xml = new SimpleXMLElement($string);
// Specify your XPath query / expression
$result = $xml->xpath('/body');
// Loop through each result XPath has returned
while(list( ,$node) = each($result)) {
echo '/body: ',$node,"\n";
}
?>
So for your xpath, do something like:
<?php
$url = ""; // Set this to url
$string = file_get_contents($url);
// Get it ready for XPath
$xml = new SimpleXMLElement($string);
// Specify your XPath query / expression
$result = $xml->xpath('/body/div[@id='div-id']');
// Loop through each result XPath has returned
while(list( ,$node) = each($result)) {
echo '/body: ',$node,"\n";
}
?>
~John
cjohnweb
Junior Poster in Training
99 posts since Apr 2010
Reputation Points: 26
Solved Threads: 8
Change one of the quote pairs tot double quotes.
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101
Do as @twiss said, or escape it.
$result = $xml->xpath('div[@id=\'player\']');
Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
That's because of the encapsulated apostrophes.
I'm not the best with XPath myself, but I've used it for some pretty slick things. I got the following code from ( http://us.php.net/manual/en/class.domxpath.php ) and I edited it to pull the content of any div with an id of player.
You may need to find another way to load the file you are working with though (save file_get_contents($file); as a file, then open it with the LoadHTMLFile function).
<?php
$file = "file.txt"; // xml formatted text file...
$doc = new DOMDocument();
$doc->loadHTMLFile($file);
$xpath = new DOMXpath($doc);
// example 1: for everything with an id
//$elements = $xpath->query("//*[@id]");
// example 2: for node data in a selected id
//$elements = $xpath->query("/html/body/div[@id='yourTagIdHere']");
// example 3: same as above with wildcard
$elements = $xpath->query("*/div[@id='player']");
if (!is_null($elements)) {
foreach ($elements as $element) {
// echo "<br/>[". $element->nodeName. "]";
$nodes = $element->childNodes;
foreach ($nodes as $node) {
echo $node->nodeValue. "\n";
}
}
}
?>
cjohnweb
Junior Poster in Training
99 posts since Apr 2010
Reputation Points: 26
Solved Threads: 8
If I understand properly, you want to find a with an id of player, then you want to take the information out of it IF that information begins with "flv_url=" and ends with "&"?
You will have to add some code at lines 22 - 25, something like:
$nodes = $element->childNodes;
foreach ($nodes as $node) {
$line_content $node->nodeValue;
preg_match('/(flv_url=).?*(&)/is',$line_content,$return);
if(!empty($return[0])){$results[] = $line_content; unset($return);}
}
?>
You will probably have to make changes to that preg_match function. I know it has to start with a "/" slash, and end with "/is", the ".?*" is like a wild card matching everything in between. I'm just not very good with regex stuff. You may also mount (I think thats what its called) that beginning with a "^" char:
preg_match("/^(flv_url=).?*(&)/is",$content,$return);
You might need to escape the =, & and ; chars.
Sorry, I am out of time. I'll check back end of today.
Good luck!
cjohnweb
Junior Poster in Training
99 posts since Apr 2010
Reputation Points: 26
Solved Threads: 8
It needs an = in between.
twiss
Veteran Poster
1,005 posts since Apr 2010
Reputation Points: 177
Solved Threads: 101