Jump to content

htmldom + substr()


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.

Edited by Ustag
Link to post
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 post
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)?

Edited by Ustag
Link to post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...