Reply to Re: SimpleXML & Google images

Your name:

Reply:


Posted by ZeldorBlat on 09/08/06 02:21

mouseit101 wrote:
> Hi, I'm writing a script that would (hopefully) search google images
> for whatever, and then return a list of URLs for the image. Right now I
> have:
>
> $dom = new DomDocument();
>
> $url = "http://images.google.com/images?q=hello";
>
> $dom->loadHTMLFile($url);
>
> $sxe = simplexml_import_dom($dom);
> foreach($sxe->xpath('//img') as $node)
> {
> echo $node->src;
> }
>
> What this is supposed to do (line by line):
> Make a new DomDocument
> Define $url
> load the HTML file from $url
> make a simpleXML object from the loaded DOM
> go through all the image tags (using a DomNodeList w/ xpath) and print
> out the src attribute of the node.
>
> What it does:
> Prints nothing.
>
> Just wondering if anyone knew what ws goin on.
> Thanks.

It prints nothing because you have error_reporting disabled in php.ini.
If you enable it you'll see what's going on. For example, here's what
happened when I ran your code:

PHP Warning: DOMDocument::loadHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7

Warning: DOMDocument::loadHTMLFile(): Unexpected end tag : head in
http://images.google.com/images?q=hello, line: 32 in foo.php on line 7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseStartTag: misplaced
<body> tag in http://images.google.com/images?q=hello, line: 32 in
foo.phpon line 7

Warning: DOMDocument::loadHTMLFile(): htmlParseStartTag: misplaced
<body> tag in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
foo.php on line 7

Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef: expecting ';'
in http://images.google.com/images?q=hello, line: 32 in foo.php on line
7
PHP Warning: DOMDocument::loadHTMLFile(): htmlParseEntityRef:
expecting ';' in http://images.google.com/images?q=hello, line: 32 in
/foo.php on line 7

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация