PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 2nd, 2000, 03:49 PM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 &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:

<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".

Reply With Quote
  #2  
Old July 2nd, 2000, 06:00 PM
polman polman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 45 polman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #3  
Old July 3rd, 2000, 04:47 PM
alexgreg's Avatar
alexgreg alexgreg is offline
Full Access
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2000
Location: London, UK
Posts: 2,019 alexgreg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 sec
Reputation Power: 15
Thanks, but whereabouts does the code go?

Reply With Quote
  #4  
Old July 3rd, 2000, 06:17 PM
polman polman is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 45 polman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #5  
Old July 4th, 2000, 02:10 PM
terium terium is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 60 terium User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Send a message via ICQ to terium
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

Reply With Quote
  #6  
Old July 4th, 2000, 02:19 PM
terium terium is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Posts: 60 terium User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Send a message via ICQ to terium
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Editing files in a &lt;textarea&gt;

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap