#1
  1. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    OK, I've written this program to let me edit ASCII files on my server in a <textarea>. However, if the file that is being edited contains a textarea within it, then I get problems...

    To cut a long story short, what I want to do is read this file into the textarea but I want to convert all of the < and > characters to &amp;lt; and &amp;gt; 's. I figgered you'd do this through Regular Expressions: however these are poorly documented in the PHP book I have, though the Perl book I have tells me how to do this. Could someone tell me how to do this, IN PHP!

    Thanks very much.

    --------------------------
    Alex
    (http://www.alex-greg.co.uk)

    oh yeah, here's the code:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    <? include("top.txt"); ?>
    <form method=POST action="save_file.php3">

    <? print "$file"; ?><br>

    <? print '<textarea name="data" rows=18 cols=170 class=text>'; ?>
    <?
    if (file_exists("$file"))
    {readfile("$file");}
    ?>
    <? print "</textarea><br><br>";

    print '<input type="hidden" name="file" value="<? print "$file"; ?>">';

    print '<input type="submit" name="submit" value="Save Changes" class="text">';

    print '</form>';

    include("bottom.txt"); ?>

    [/code]

    The program gets send a variable by the calling form called "file".
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    15
    $file = eregi("<","<",$file);
    $file = eregi(">",">",$file);

    If you want a good place to look for info, www.php.net has a searchable list of all the functions and explains them fairly well.
  4. #3
  5. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Thanks, but whereabouts does the code go?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    15
    Man, the 2nd "<" and the 2nd ">" should be the & lt; and the & gt; ... it just displayed it wrong. Anyway that should go after the readfile.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    60
    Rep Power
    15
    Actually, what you want is htmlspecialchars(). This will change &, ", <, and > to HTML entities.

    So, if you have:
    $string = "<html></html>";

    and do this:
    $string = htmlspecialchars($string);
    echo $string;

    you'll get this:
    <html></html>

    HTH
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    60
    Rep Power
    15
    Actually, what you want is htmlspecialchars(). This will change &, ", <, and > to HTML entities.

    So for every print() statement that you have with < or >, do this (not tested):
    print htmlspecialchars('<textarea or something>');

    HTH

Similar Threads

  1. Can't move or delete it!
    By Hykinsel007 in forum Windows Help
    Replies: 3
    Last Post: June 15th, 2004, 03:41 PM
  2. How can I pack servlet files into a jar file?
    By suryahema in forum Java Help
    Replies: 1
    Last Post: December 18th, 2003, 08:32 AM
  3. Editing Class Files?
    By garymantle in forum Java Help
    Replies: 0
    Last Post: December 3rd, 2003, 11:21 AM
  4. php editing zone files
    By smiled in forum DNS
    Replies: 5
    Last Post: December 2nd, 2003, 02:52 PM
  5. editing text files in form textareas?
    By ralphuk100 in forum PHP Development
    Replies: 1
    Last Post: November 9th, 2003, 10:09 PM

IMN logo majestic logo threadwatch logo seochat tools logo