Jump to content

htmldom + substr()


Ustag

Recommended Posts

Hi, I am scraping a game page in order to grab certain info about a player. What I scrape is the info under "Character Deaths" for example on this page: http://www.tibia.com...s&name=Brunkarn This code will print all killed players in April:

if((substr($td2->nodeValue, 0, 3) == "Apr") && (substr($td2->nextSibling->nodeValue, 0, 6) == Killed)){echo $player.': '.substr($td2->nodeValue, 0, 7).'<br>';}

It prints "Brunkarn: Apr 08". now if I replace this:

substr($td2->nodeValue, 0, 3) == "Apr")

with this:

substr($td2->nodeValue, 0, 7) == "Apr 08")

I get no result anymore, why? When I echo substr($td2->nodeValue, 0, 7) I get "Apr 08". Sorry if I post in wrong section, please move this.

Link to comment
Share on other sites

Instead of 0, 7 it should be 0, 6 becausse there are only 6 characters there. You forgot to put quotation marks around the word "Killed"If you have error messages activated it would showsomething like this: Use of undefined constant Killed, assuming "Killed"

Link to comment
Share on other sites

Adding "Killed" and using substr($td2->nodeValue, 0, 6) == "Apr 08" did not work eather. And how come echo substr($td2->nodeValue, 0, 7) = "Apr 08" and echo substr($td2->nodeValue, 0, 6) = "Apr 0"? I just noticed in their source code it says "Apr& #160;08", what is "& #160;" (without the whitespace)?

Link to comment
Share on other sites

var_dump(substr($td2->nodeValue, 0, 3)); = string(3) "Apr"var_dump(substr($td2->nodeValue, 0, 4)); = string(4) "Apr�"var_dump(substr($td2->nodeValue, 0, 5)); = string(5) "Apr "var_dump(substr($td2->nodeValue, 0, 6)); = string(6) "Apr 0"var_dump(substr($td2->nodeValue, 0, 7)); = string(7) "Apr 08" Does this tell me anything? ^^

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...