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
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Get PART of a file (via ID)

    So I want to get part of a file, specifically everything WITHIN the div id="left". I have this code, but it gets the whole file. I want to use this to edit a remote file (test.html).
    PHP Code:
    <?
    $myHTMLFile 
    "test.html";
    $myHTML implodefile$myHTMLFile ), "" );

    if ( 
    $save ) {
    $tmpfile fopen$myHTMLFile"w" );
    $fp fwrite$tmpfile$myHTMLText );
    fclose($tmpfile);
    }
    ?>

    <html>
    <head>
    <title>Update.php</title>
    </head>
    <body>
    <div align=center>
    <form action="update.php">
    <textarea name="myHTMLText" rows=35 cols=70><? echo $myHTML ?></textarea>
    <br>
    <input type="submit" name="save" value="save">
    </form>
    </div>
    </body>
    </html>
    .
    The above file will be for example Update.php

    I just edited this, what was written here before is no longer needed, just the part about getting part of the file via ID.
    Last edited by croatiankid; 03-06-2007 at 08:24 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You would have to use preg_replace() or ereg_replace() to search the file to replace the text. Ex.:
    PHP Code:
    $line preg_replace('/<div id="left">(.*)<\/div>/'$newtext$line); 
    Or preg_match() to just get the text.

  • #3
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts
    So how would I use that in the above code? I didn't write the above code and don't really understand arrays (only basic PHP). I mean I see how I can get the text, but firstly I need to tell it to stop at the first </div> after, then i need to get that text in the text area, and THEN I need to replace it.

    Another thing: would this be easier with just a simple .txt file that would be included in the div, and in effect this script would just edit the txt file? hmm yes I think I"ll do it that way?
    Last edited by croatiankid; 03-06-2007 at 09:59 PM.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    would this be easier with just a simple .txt file that would be included in the div, and in effect this script would just edit the txt file? hmm yes I think I"ll do it that way?
    Easier, and more reliable.

    And arrays are your friend, practice using them. They're really simple yet powerful.


  •  

    Posting Permissions

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