2

I'm trying to parse some html with a php document that I upload to my web host. When I try this (with the last echo in there just to see if it works):

<?php
//a URL you want to retrieve
$my_url = 'http://pointstreak.com/prostats/standings.html?leagueid=49&seasonid=12983';
$html = file_get_contents($my_url);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);

//Put your XPath Query here
$my_xpath_query = "//div[@id='statscontainer']/table/tr/td/table[@class='tablelines']/tr/td";
$result_rows = $xpath->query($my_xpath_query);

// Create an array to hold the content of the nodes
$standingsArray = array();

//here we loop through our results (a DOMDocument Object)
foreach ($result_rows as $result_object){
    $standingsArray[] = $result_object->childNodes->item(0)->nodeValue;
}

// Remove the first 12 observations from $standingsArray (table headers)
for ($i = 0; $i < 12; $i++) {
    unset($standingsArray[0]);
    $standingsArray = array_values($results_rows);
}

// Remove the 12 observations at index 96 (table headers)
for ($i = 0; $i < 12; $i++) {
    unset($standingsArray[96]);
    $standingsArray = array_values($results_rows);
}

foreach ($standingsArray as $arrayValue) {
    echo $arrayValue;
}

echo “HEYHEY”;

?>

The output on my webpage is: “HEYHEYâ€

However, if I change the line

foreach ($standingsArray as $arrayValue) {
        echo $arrayValue;
    }

to:

foreach ($standingsArray as $arrayValue) {
        echo "$arrayValue";
    }

then even the "“HEYHEYâ€" goes away and all I have is a blank webpage.

Jay
  • 17
  • 1
  • 1
  • 5
  • http://ideone.com/YB8vZY – Alex Apr 22 '15 at 18:06
  • Add error reporting to the top of your file(s) right after your opening ` – Jay Blanchard Apr 22 '15 at 18:09
  • 1
    This is not a php error. You have a character set mismatch. e.g. dumping utf-8 text into an iso-8859 display environment. – Marc B Apr 22 '15 at 18:11
  • It looks like your quotes around HEYHEY are kinda funky. I think you have a left double quotation mark instead of a regular quotation mark. See this http://stackoverflow.com/questions/18735921/are-there-different-types-of-double-quotes-in-utf-8-php-str-replace. Also, I think the document you are trying to upload is empty, or it's not getting it. – Katrina Apr 22 '15 at 18:14
  • How can I fix my character set mismatch? – Jay Apr 22 '15 at 18:22

1 Answers1

0

Try this,

foreach ($standingsArray as $arrayValue) 
{
    echo utf8_encode($arrayValue);
}

UPDATE:

"HEYHEY" seems to be a different font, try removing/replacing it with normal text.

Nandan Bhat
  • 1,573
  • 2
  • 9
  • 21
  • No luck. Thanks though. – Jay Apr 22 '15 at 18:37
  • The last echo was not an ordinary text, I opened in notepad++ and deleted the echo and typed again, it's running correctly. – Nandan Bhat Apr 22 '15 at 18:44
  • Oh my god you're right. How did you discover that? Does notepad++ warn you of things like that? I would have never been able to do that myself. Wow, thanks. Now I just need to resolve all these warnings and issues. – Jay Apr 22 '15 at 18:48
  • No warning, nothing, Just tried with different values, then I got to know. – Nandan Bhat Apr 22 '15 at 18:49
  • Wow. What a strange bug. Well thank you tons. I wish I could upvote your comment but I don't have enough reputation. – Jay Apr 22 '15 at 19:20