0

I am trying to figure out what is the best way to make this work, I am new to php. I was able to make my script work to find specific data on my htm file with the following script tested on my local server.

<?php

include ('simple_html_dom.php');

//create DOM from URL or local file
$html = file_get_html ('Lotto Texas.htm');

//find td class name currLotWinnum and store in variable winNumbers
foreach($html ->find('td.currLotWinnum') as $winNumbers)

    //print winNumbers
    echo "<b>The winning numbers are</b><br>";
    echo $winNumbers -> innertext . '<br>';

?>

Need some light here, ultimately I would like to create a web service to return json format and access that data from my iOS application using NSJSONSerialization class.

thefern
  • 367
  • 7
  • 19

1 Answers1

0

Instead of echoing the results as ordinary text for the user, you need to put it in a data structure (an array in this case) and then use json_encode to serialize it.

$results = array();
foreach ($html->find('td.curLotWinnum' as $winNumbers) {
  $results[] = $winNumbers->innertext;
}
echo json_encode($results);
Barmar
  • 741,623
  • 53
  • 500
  • 612