The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Editing files in a <textarea>
Discuss Editing files in a <textarea> in the PHP Development forum on Dev Shed. Editing files in a <textarea> PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 2nd, 2000, 03:49 PM
|
 |
Full Access
|
|
Join Date: Jun 2000
Location: London, UK
Posts: 2,019
Time spent in forums: 3 sec
Reputation Power: 15
|
|
|
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 < and > '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".
|

July 2nd, 2000, 06:00 PM
|
|
Contributing User
|
|
Join Date: Jul 2000
Posts: 45
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
$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.
|

July 3rd, 2000, 04:47 PM
|
 |
Full Access
|
|
Join Date: Jun 2000
Location: London, UK
Posts: 2,019
Time spent in forums: 3 sec
Reputation Power: 15
|
|
|
Thanks, but whereabouts does the code go?
|

July 3rd, 2000, 06:17 PM
|
|
Contributing User
|
|
Join Date: Jul 2000
Posts: 45
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
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.
|

July 4th, 2000, 02:10 PM
|
|
Contributing User
|
|
Join Date: Jun 2000
Posts: 60
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
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
|

July 4th, 2000, 02:19 PM
|
|
Contributing User
|
|
Join Date: Jun 2000
Posts: 60
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|