SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Washington, DC
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using the DOM in php5

    So the structure is like this in XML.

    <ResultSet>
    <Results>
    <Results>
    </ResultSet>

    So basically what I'm trying to do is pull information from a db, send it to yahoo's term extractor, get the results back in XML and parse it. To parse it I was using dom and I have the following code.

    PHP Code:
    $dom = new DOMDocument('1.0''UTF-8');
    if (
    $dom->loadXML($response) === false) {
       die(
    'Parsing failed');
    }

      
    $dom->loadXML($response);
      
      
    $ResultSets $dom->getElementsByTagName"ResultSet" );
      foreach( 
    $ResultSets as $ResultSet )
      {
      
    $RResults $ResultSet->getElementsByTagName"Results" );
      
    $Results $ResultSets->item(0)->nodeValue;

      echo 
    "<h1>DOM Results</h1> $Results";
      } 
    <ResultSet>
    <Results>Bush</Results>
    <Results>President</Results>
    <Results>United States</Results>
    </ResultSet>

    However the results get outputted as such, "bushpresident united states". I want to get a comma in between each result how should I go about doing that? Oh and if you need a better idea of what I'm doing this is what I have so far http://www.pixellab.org/yte.php5

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may want to check your code again there at the end, I think you don't use the proper variable to get the value.

    Also try to use less confusing var names, it will save you in the future.
    David

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Washington, DC
    Posts
    158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ClickHeRe View Post
    you may want to check your code again there at the end, I think you don't use the proper variable to get the value.

    Also try to use less confusing var names, it will save you in the future.
    Yeah they are a bit confusing, I'll go ahead and fix that. I guess I'll do a little more digging to see the proper variable I should use though. Thanks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •