Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP editing html pages
Old 05-18-2009, 09:06 AM PHP editing html pages
Skilled Talker

Posts: 87
Trades: 0
Hi everyone!

I'm currently trying to implement a feature for some of my members to edit their own html pages using php. It's pretty simple code,

Code:
$handle = fopen($filename, "r"); 
$contents = fread($handle, filesize($filename));
echo "<form method=\"post\" action=\"admin.php?action=edit\"> 
	<strong>$filename</strong><br> 
	<input type=\"hidden\" name=\"file\" value=\"$filename\"> 
	<textarea name=\"content\" cols=\"100\" rows=\"40\">".$contents."</textarea><br> 
	<input type=\"submit\" name=\"update\" value=\"Update\"> 
	</form>"; 
fclose($handle);
And then updating it:

Code:
$filename = $_POST['file'];	
	if(is_writable($filename)) { 
	$handle = fopen($filename, "w+");
	$content = stripslashes($_POST['content']);
	fwrite($handle, $content); 
	fclose($handle);
it works just fine except that after I save it, all my encoded characters become decoded. &nbsp; becomes a space, &copy; becomes ©, etc. How should I prevent that??? Thanks!
__________________

Please login or register to view this content. Registration is FREE
- The most comprehensive online resource for students and educators.
yuechen is offline
Reply With Quote
View Public Profile Visit yuechen's homepage!
 
 
Register now for full access!
Old 05-18-2009, 09:43 AM Re: PHP editing html pages
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
fwrite($handle, htmlentities($content));
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 05:48 PM Re: PHP editing html pages
Skilled Talker

Posts: 87
Trades: 0
No, no I don't want all of my entities destroyed! Tags are still pretty useful in html.

I want to keep both my tags, and those elements that I've encoded with &. For example:

Code:
<html>
<head></head>
<body>
<p>These are some spaces &nbsp; &nbsp; &nbsp; &nbsp; </p>
</body>
</html>
When I copy that back into the file, I don't want php to make it

Code:
<html>
<head></head>
<body>
<p>These are some spaces      </p>
</body>
</html>
How do I do that??? thanks.
__________________

Please login or register to view this content. Registration is FREE
- The most comprehensive online resource for students and educators.
yuechen is offline
Reply With Quote
View Public Profile Visit yuechen's homepage!
 
Old 05-18-2009, 06:27 PM Re: PHP editing html pages
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
OK I see, you would want to use the htmlentities() function when you output within your textarea because the browser will pass the interpeted data.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 05-18-2009, 06:36 PM Re: PHP editing html pages
Skilled Talker

Posts: 87
Trades: 0
Ah, works like a charm!!!

Thank you so much!
__________________

Please login or register to view this content. Registration is FREE
- The most comprehensive online resource for students and educators.
yuechen is offline
Reply With Quote
View Public Profile Visit yuechen's homepage!
 
Reply     « Reply to PHP editing html pages
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.17248 seconds with 12 queries