Ustag Posted April 9, 2012 Share Posted April 9, 2012 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 More sharing options...
Ingolme Posted April 9, 2012 Share Posted April 9, 2012 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 More sharing options...
Ustag Posted April 9, 2012 Author Share Posted April 9, 2012 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 More sharing options...
justsomeguy Posted April 9, 2012 Share Posted April 9, 2012 There may be something like a space before the value. If you save that value to a variable you can use var_dump and it will show you the type and length of the value. Link to comment Share on other sites More sharing options...
Ustag Posted April 10, 2012 Author Share Posted April 10, 2012 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 More sharing options...
Ingolme Posted April 10, 2012 Share Posted April 10, 2012 The character is a non-breaking space. It's not the same as an ordinary space. Link to comment Share on other sites More sharing options...
Ustag Posted April 10, 2012 Author Share Posted April 10, 2012 Thank you all but my solution will be to break this down and add substr($td2->nodeValue, 0, 3) and substr($td2->nodeValue, 5, 2) in to variables that will give me "Apr" and "08". Thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.