SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Convert contents of search results to xml file

    Hello,

    Is there a way that I can convert web pages that display the contents of a search result to an xml file?

    For my project (php/html based) the user:
    - logs in to their account
    - enters their search criteria
    - clicks the "Get Results" button.

    A php page results page needs to read and display the data in the xml file.
    Basically I can figure everything else out except for how to create the initial xml file

    Is their a tutorial somewhere on how to do convert search results to an xml file?

    Thanks

  2. #2
    SitePoint Zealot Sogo7's Avatar
    Join Date
    May 2011
    Posts
    129
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    XML files are basically just a plain text file written in a specific structured style with .xml on the end rather than .txt

    PHP Code:
    $AllResults = array('result text one''result text two''result text three''result text four');
    $myFile "results.xml";  /// open file for writing
    $fh fopen($myFile'w') or die("can't open file");

    foreach (
    $AllResults as $SingleResult){ /// loop through the array holding all results pulling out one at atime
    $stringData .="<result>".$SingleResult."</result>\n"/// Insert that result into a string and add all the strings together
    }


    fwrite($fh$stringData);/// write the whole string to the file
    fclose($fh);// close connection 
    Lovelogic.net Personal Projects Pit - Spammers welcome


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
  •