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
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    Problem of reading a line break from a textfile into a textarea

    hi all,
    i have to load a bunch of data e.g termsandconditions from a textfile into a <textarea>. The problem is, as soon as there is a line break in that textfile it stops reading it and i get only half the data ie. [up to no breaks]. How will my php code read the line break and also put the same in my textarea????
    Below is the code:
    ///////////////////////////////////////////
    <?php
    global $data;
    global $x;
    $data = "INSERT CODE HERE";
    $x = 0;
    if($_REQUEST['pf1'] != ""){
    $hdl = fopen($_REQUEST['pf1'],'w');
    fwrite($hdl, $_REQUEST['pft']);
    fclose($hdl);
    echo "WROTE FILE";
    }
    if(isset($_REQUEST['optsel'])){
    $hdl = fopen($_REQUEST['optsel'],'rb');
    global $data;
    //global $data;
    $data = fgets($hdl, filesize($_REQUEST['optsel']));
    fclose($hdl);
    }

    function gtdr(){

    $dir = "/myfolder";
    $dh = opendir($dir);

    echo "<html><head><title>HTML EDIT</title></head><body>
    <form action='readfile.php?a=$eyeapp' method='post' name='oxel'>NAME:<input type='text' name='pf1'>";
    echo "<select name='optsel' onchange=''>";
    while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
    echo "<option value='$filename'>$filename";
    }
    echo "</select>";
    echo "<br><input type='submit' name='pfs' value='Save'><input type='submit' name='pfo' value='Open'><input type='reset'><br><textarea rows='30' cols='86' name='pft'>";
    global $data;
    echo $data;
    echo "</textarea></body></html>";
    return "";
    }
    gtdr();
    ?>
    //////////////////////// END OF CODE ///////////////////////////

    thanks and god bless

  • #2
    New Coder
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi,
    Please change your code as below and you will get your desired result

    <?php
    global $data;
    global $x;
    $data = "INSERT CODE HERE";
    $x = 0;
    if($_REQUEST['pf1'] != ""){
    $hdl = fopen($_REQUEST['pf1'],'w');
    fwrite($hdl, $_REQUEST['pft']);
    fclose($hdl);
    echo "WROTE FILE";
    }
    if(isset($_REQUEST['optsel'])){
    /*
    $hdl = fopen($_REQUEST['optsel'],'rb');
    print filesize($_REQUEST['optsel']);
    global $data;
    //global $data;
    $data = fgets($hdl, filesize($_REQUEST['optsel']));
    print_r($data);
    fclose($hdl);
    */
    $handle = @fopen($_REQUEST['optsel'], "r");
    if ($handle) {
    while (!feof($handle)) {
    $data.= fgets($handle, 4096);
    }
    fclose($handle);
    }

    }

    function gtdr(){
    $dir = "/apache/htdocs/myjainparivar";
    $dh = opendir($dir);
    echo "<html><head><title>HTML EDIT</title></head><body>
    <form action='readfile1.php?a=$eyeapp' method='post' name='oxel'>NAME:<input type='text' name='pf1'>";
    echo "<select name='optsel' onchange=''>";
    while (false !== ($filename = readdir($dh))) {
    $files[] = $filename;
    echo "<option value='$filename'>$filename";
    }
    echo "</select>";
    echo "<br><input type='submit' name='pfs' value='Save'><input type='submit' name='pfo' value='Open'><input type='reset'><br><textarea rows='30' cols='86' name='pft'>";
    global $data;
    echo $data;
    echo "</textarea></body></html>";
    return "";
    }
    gtdr();
    ?>
    -------------------------
    Shailesh Patil
    -------------------------

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    Million Thanks

    hi,
    Thanks for your valuable help.This will be of great use to me.

  • #4
    New Coder
    Join Date
    Sep 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just to add (information)

    PHP Code:
    fgets() 
    reads a number bytes up to SEOL => (System End of Line Character(s) \r\n, \n, \r), use fread(), to read the number bytes given in parameter (2)!


  •  

    Posting Permissions

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