Well, you cannot do a loop without PHP, so your HTML should be inside the loop. But you can return a simplified array from your function if this helps:
function off($limit) { $string = file_get_contents("feed.xml"); $xml = simplexml_load_string($string); $return = array(); foreach ($xml->FOUND->CAT as $place) { $return[] = array( 'limits' => $place->CORDS, 'rate' => $place->STARS, 'phone' => $place->PHONE ) } return $return; }
The function now creates an array of results returned back to the caller. Then you can just skip this array:
<html> <body> <?php $arr = off('57854'); ?> <table width="200" border="1"> <?php foreach($arr as $row): ?> <tr> <td><?php echo $row['limits']; ?></td> <td><?php echo $row['rate']; ?></td> <td><?php echo $row['phone']; ?></td> </tr> <?php endforeach; ?> </table> </body> </html>
This way you can avoid HTML inside your function, which is always good to do - keep your logic separate from the presentation.
source share