Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts

    DomDocument get content in text file

    Hello!

    I was able to get the content by ID and tag names, but I am wondering how can I just get all the contents from a text file (which doesn't have any markup)?

    PHP Code:
    <?php
    $doc 
    = new DomDocument;
    $doc->validateOnParse true;
    $doc->loadHtml(file_get_contents("test.html"));
    $t = ($doc->getElementById("patch"));
    print 
    $t->nodeValue;
    ?>
    Thanks
    Last edited by RonnyNishimoto; 08-15-2012 at 03:39 AM.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    $lines=file("mytextfile.txt");
    foreach($lines as $line){
    echo $line;
    }

  • Users who have thanked mlseim for this post:

    RonnyNishimoto (08-14-2012)

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yep, or file_get_contents, or standard fopen/fread.
    DOM is only useful if it has an actual document object model to process. Flat files require a flat reading technique.

  • Users who have thanked Fou-Lu for this post:

    RonnyNishimoto (08-14-2012)

  • #4
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Haha, yeah I was probably going overboard on Dom, I just discovered it.

    Thanks guys!


  •  

    Posting Permissions

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