★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/001727.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  PHP
  Editing files in a <textarea>

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   Editing files in a <textarea>
alexgreg
Member
posted July 02, 2000 02:49 PM     Click Here to See the Profile for alexgreg   Click Here to Email alexgreg     Edit/Delete Message Reply w/Quote
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 &lt; and &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:

code:

<? include("top.txt"); ?>
<form method=POST action="/old?u=http%3A%2F%2Fwww.devshed.com%2FTalk%2FForums%2FForum5%2FHTML%2Fsave_file.php3&y=1999">

<? 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"); ?>


The program gets send a variable by the calling form called "file".

polman
Member
posted July 02, 2000 05:00 PM     Click Here to See the Profile for polman     Edit/Delete Message Reply w/Quote
$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.

alexgreg
Member
posted July 03, 2000 03:47 PM     Click Here to See the Profile for alexgreg   Click Here to Email alexgreg     Edit/Delete Message Reply w/Quote
Thanks, but whereabouts does the code go?

polman
Member
posted July 03, 2000 05:17 PM     Click Here to See the Profile for polman     Edit/Delete Message Reply w/Quote
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.

terium
Member
posted July 04, 2000 01:10 PM     Click Here to See the Profile for terium   Click Here to Email terium     Edit/Delete Message Reply w/Quote
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

terium
Member
posted July 04, 2000 01:19 PM     Click Here to See the Profile for terium   Click Here to Email terium     Edit/Delete Message Reply w/Quote
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

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.