ApocalypeX Posted August 4, 2010 Share Posted August 4, 2010 I have a script that I wrote for an application that grabs data off of another site. I started noticing the other day that underscores where not being grabbed from pages.I'm using $USERNAME = $dom->getElementById("ctl00_mainContent_header_lblUsername")->nodeValue; Is there a way to fix this? Link to comment Share on other sites More sharing options...
boen_robot Posted August 4, 2010 Share Posted August 4, 2010 Are you sure it's just IDs with underscores, or is it all IDs?You need to either load the page with loadHTMLFile() (if it's an HTML page), or with load(), along with one of the two things specified on the getElementById() manual page. Link to comment Share on other sites More sharing options...
ApocalypeX Posted August 5, 2010 Author Share Posted August 5, 2010 Are you sure it's just IDs with underscores, or is it all IDs?You need to either load the page with loadHTMLFile() (if it's an HTML page), or with load(), along with one of the two things specified on the getElementById() manual page.I have no way of checking as that ID is the only element that can have a underscore in it. But if my memory serves me well nodeValue removes all special chars? Could it be reading the underscore as one? Is there another method than nodeValue I can use in my DOM to return the string? Link to comment Share on other sites More sharing options...
boen_robot Posted August 5, 2010 Share Posted August 5, 2010 Wait... so the problem is not fetching the content of elements that have an ID with an underscore. It's that their contents gets fetched, but without the underscores in it. Is that right?Could you show the page in question and/or a more complete sample of the PHP code used. Link to comment Share on other sites More sharing options...
ApocalypeX Posted August 5, 2010 Author Share Posted August 5, 2010 Yep the problem is not grabbing the data, it's the data thats grabbed. $url = "http://www.bungie.net/Account/profile.aspx?uid=1919181"; $html= file_get_contents($url); $dom = new DOMDocument(); libxml_use_internal_errors(true); if (!$dom->loadHTML($html)) { echo libxml_get_last_error()->message; } $USERNAME = $dom->getElementById("ctl00_mainContent_header_lblUsername")->nodeValue; Link to comment Share on other sites More sharing options...
boen_robot Posted August 6, 2010 Share Posted August 6, 2010 Running that piece of code, with no additions but an echo of the $USERNAME produces the expected result: Gamerz_Property If that's not what you're getting, there are two possibilities:1. Another piece of code further down the line is stripping the userscores away.2. You have a really old version of PHP that happens to have such a bug. I'm using PHP 5.3.2, but I don't think any of the PHP 5.2 branch has this problem. Link to comment Share on other sites More sharing options...
ApocalypeX Posted August 6, 2010 Author Share Posted August 6, 2010 Running that piece of code, with no additions but an echo of the $USERNAME produces the expected result:Gamerz_Property If that's not what you're getting, there are two possibilities:1. Another piece of code further down the line is stripping the userscores away.2. You have a really old version of PHP that happens to have such a bug. I'm using PHP 5.3.2, but I don't think any of the PHP 5.2 branch has this problem. I've echoed the username throughout my entire script. I'm using 5.1 I'll try to update it and see if that fixes it.But thanks Link to comment Share on other sites More sharing options...
ApocalypeX Posted August 9, 2010 Author Share Posted August 9, 2010 Updating it worked. It now grabs the underscore. I can't believe something like this wasn't in previous versions. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.