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 7 of 7

Thread: Problem

  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Problem

    I have a problem - I made a code that allows me to read files in a textarea.
    Now what I see in the text area is basically the source of the file :

    And I want people to edit only their text, the problem is that people can see also the code. What I want it, is to look like this: so people could see everytext in the file that they uploaded in it's size, and decoration.

    How can I do this ? I can't seem to understand this.
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
     "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      
    <html xmlns="http://www.w3.org/1999/xhtml">
    <body>
    <?php
    //file to read

    $file "C:\wamp\www\New Folder\cpl.php";

    // file open

    $fo fopen("$file""r") or die("Could not find '$file'!");

    //read the file

    $fr fread($fofilesize($file)) or die("Could not read '$file'!");

    //close the file

    $fc =  fclose($fo) ;


    ?>
    <center>
    <textarea cols='118' name="txtbox" rows='15' class='textarea'><?php echo $fr?></textarea>
    </center>
    </body>
    </html>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    That's called RTF (Rich Text Formatting).
    You need to use a script like TinyMCE ...
    http://www.tinymce.com/

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    That's not it, I might use this script later, but now what i want is that in the textarea it will display only the text which in the file I want to read.
    Can any one show me what to add to my script in order to achieve that?.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Call this script "edit.php" and see if it works for you ...

    PHP Code:
    <?php
    $action
    ="";

    if(isset(
    $_POST['action'])){
    $action=$_POST['action'];
    }
    if(isset(
    $_POST['textarea'])){
    $textarea=$_POST['textarea'];
    }

    $url "C:\wamp\www\New Folder\cpl.php";
    if (
    file_exists($url)) {
    // do nothing
    } else {
    echo 
    "File does not exist.";
    exit;
    }

    // Get page
    $data implode(""file($url)); 

    if(
    $action=="save"){
    $newtext=stripslashes($textarea);
    $newtext str_replace("<?"""$newtext);
    $newtext str_replace("?>"""$newtext);
    $newtext nl2br($newtext);
    $fh fopen($url'w') or die("can't open file");
    fwrite($fh$newtext);
    fclose($fh); 
    header ("location: edit.php");
    }
    else{
    echo
    "
    <html>
    <head><title>Text Editor</title>
    <style>
    body,html{
    margin:0px auto;
    width:700px;
    text-align:center;
    }
    #content{
    margin:0px auto;
    width:700px;
    }
    #middle h1 {
        color: transparent;
        font-family:georgia;
        font-size:12pt;
        margin:0;
        color: #dF9100;
        padding:10px 0px 15px 0px;
        text-align:left;
    }
    </style>
    <body>
    <div id='content'>
    "
    ;

    $ta=br2nl($data);

    echo
    "
    <a href='$return'><-- Return to Page</a><br /><br />
    Make Changes and click \"Save Changes\" at the very bottom ...<br />
    <form action='edit.php' method='post'>
    <input type='hidden' name='action' value='save'>
    <textarea name='textarea' rows='25' cols='80'>$ta</textarea>
    <br />
    <input type='submit' name='submit' value='Save Changes'>
    </form>

    <div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'>
    "
    ;
    echo
    "
    </div>
    </div>
    </body>
    </html>
    "
    ;
    }

    function 
    br2nl($str) {
    return 
    preg_replace('=<br */?>=i'""$str);
    }

    ?>

    .

  • Users who have thanked mlseim for this post:

    java001 (02-20-2012)

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you very much, this was very helpful to me.
    One last question - when the file I want to edit opens I see it with it's tags <html> <?php etc. - is there an option to make only the text appear in the textarea ? and not the code ?
    for example:
    I have in the file this code:

    <h1>Heading 1<h1>
    <br />
    <p>New content!</p>
    <input type='submit' value='submit'/>
    <br />
    <img src='bla.jpg' width='500px'/>

    I want to see in the textarea not the code above but it's output not the buttons nor images just the plain text:

    Heading 1
    New content!
    Last edited by java001; 02-20-2012 at 06:35 PM.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,503
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You can strip HTML ....

    But the problem is, when you edit the text and submit it for saving,
    your HTML cannot be put back in. That's sort of the point I was making
    in post #2. You want an actual "HTML text editor". That can't be done
    without using some sort of mixed PHP/javascripting ... which is AJAX,
    JQuery, things like that.

    So, look at these google results and find some very simple editors, and some
    more complicated ones. Some are simple javascripting.

    http://www.google.com/search?q=php+s...or&btnG=Search

    EDIT:
    This one looks interesting (I haven't tried it though):
    http://www.knowledgesutra.com/forums...nd-javascript/


    .

  • Users who have thanked mlseim for this post:

    java001 (02-20-2012)

  • #7
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thank you very much, I understand now.


  •  

    Posting Permissions

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