Search code examples
phpsyntaxsimplexmlphp-5.2

using ' and " in php syntax


Possible Duplicate:
How to get useful error messages in PHP?

Ive started on part of my new year resolution and decided to learn php, as part of it im trying to parse in an xml feed, and echo out the name of the events wrapped in <a> tags linking them back to the events page on the xml feed's site.

I think ive got it all in but i cant seem to see why this isnt working im just getting a blank page, if some one could point me in the right direction it would be much appreciated, cheers

<?php 
  // F1 W/H xml feed
  $xml = simplexml_load_file('http://whdn.williamhill.com/pricefeed/openbet_cdn?action=template&template=getHierarchyByMarketType&classId=5&marketSort=HH&filterBIR=N');

  foreach ($xml->response->williamhill->class->type as $type) {
    $type_attrib = $type->attributes();
    echo "<h2>".$type_attrib['name']."</h2>"; //Title - in this case f1 championship
} ?>


<ul>
  <?php 
      foreach($type->market as $event) {
          echo "<li>";
          echo "<a href="$event_attributes['url']">";
          echo $event_attributes['name'];
          echo "</a>";
          echo "</li>";
      }
  ?>
</ul>

Solution

  • echo "<a href="$event_attributes['url']">";
    

    try changing that line to

    echo "<a href=\"".$event_attributes['url']."\">";
    

    The Php parser is pretty funny about this. Usually you pick one and just stick to it, or use both single quotes and double quotes as you please. Just remember that strings with double quotes are parsed for variables.

    $hello = "Hello";
    echo "$hello master";
    

    is the same as

    $hello ="Hello";
    echo $hello.' master';