Current location: Hot Scripts Forums » General Web Coding » JavaScript » [SOLVED] Dont touch my code


[SOLVED] Dont touch my code

Reply
  #1 (permalink)  
Old 07-11-08, 03:27 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Question [SOLVED] Dont touch my code

In relation to the post strip_tags or htmlspecialchars I actually need the reverse.

I have a area where my code is saved and then loaded back into the page. The problem is, and Im sure Ive never had this problem before on previous installs of PHP, is that all html characters are encoded to & lt; and & gt; for the < >. which is not good when I load the html up as its just a block of code instead of actually being HTML. I thought I could correct this after I stripslashes then run html_entity_decode but it doesnt do anything. Since the world of encoding is a complex ever-changing subject and my basic foundations seem to have slipped away from me Im in need of help.


Quote from tizag.com.
Quote:
The htmlentities function takes a string and returns the same string with HTML converted into HTML entities. For example, the string "<script>" would be converted to "&lt;script&gt;".

By converting the < and > into entities, it prevents the browser from using it as an HTML element and it prevents the code from running if you were to display some user's input on your website.
Even tizag describes it as the way I thought it worked but it doesnt. Im not sure but does the fact that the file is xhtml have anything to do with it?

Thanks
Dal
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #2 (permalink)  
Old 07-11-08, 05:09 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Reply With Quote
  #3 (permalink)  
Old 07-11-08, 05:25 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by wirehopper View Post
Thanks wirehopper but Ive already tried this.

Quote:
"I thought I could correct this after I stripslashes then run html_entity_decode but it doesnt do anything."
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #4 (permalink)  
Old 07-11-08, 05:28 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Can you post? Sounds more like an error on your side.
Reply With Quote
  #5 (permalink)  
Old 07-11-08, 06:23 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Sure Nico

PHP Code:


<?php


PublishPage
();

function 
PublishPage()
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
//<![CDATA[

function LoadBox()
{
    document.getElementById('test').innerHTML = document.getElementById('CodeArea').innerHTML;
}

//]]>
</script>
</head>

<body>

<form action="" method="post">

  <img id="writeback" tabindex="1" value="writeback" src="somejpg.jpg" alt="writeback" onclick="LoadBox();" />
  <input name="testbutton" type="image" id="testbutton" tabindex="1" value="Save" src="aomejpg.jpg" alt="Save"  />  

<div id="test"></div>

<textarea name="CodeArea" id="CodeArea" ><?php echo html_entity_decode(stripslashes($_POST['CodeArea'])); ?></textarea>


</form>
</body>
<html>
<?php
}
?>
The project is alot bigger than this but this is the part I cant get to work.

Anyway, to test it simply copy some html into the text area ie

HTML Code:
<div>some sample text</div>
Click save to $_POST is back to the form and auto populate the text area then use the javascript function to write the contents over to the div.

Thanks

OOPS = I had a few mistakes in my above example. That should work now. Maybe its the javascript side thats causing my issues. I never thought to check. ?? Im unsure though because I use a javascript function to copy the html into the text area in my main project so I would know if its js thats causing the convert.
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."

Last edited by DAL; 07-11-08 at 06:38 PM. Reason: Im a plonka! Example code didnt work. Now Corrected
Reply With Quote
  #6 (permalink)  
Old 07-12-08, 10:18 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Spin

Ive uploaded the script so it will be easy for anyone to test what I mean.

Simply enter something like
HTML Code:
<div>Some sample text</div>
into the text area then click "Save" then when the page refeshes click "Writeback"


As you can see it writes

"<div>Some sample text</div>"
code = &lt;div&gt;Some sample text&lt;/div&gt;


instead of
"Some sample text"
code = <div>Some sample text</div>
Attached Files
File Type: zip test.zip (648 Bytes, 23 views)
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #7 (permalink)  
Old 07-12-08, 11:44 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Through further testing I have found it to be a javascript error. (Please move my post to Javascript)

Original;
HTML Code:
document.getElementById('test').innerHTML = document.getElementById('CodeArea').innerHTML;
modified;
HTML Code:
document.getElementById('test').innerHTML = document.getElementById('CodeArea').value;
Who would have 'funk it' eh!
Obvously no-one in here (PHP discussion)
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."

Last edited by DAL; 07-12-08 at 11:45 AM. Reason: BBcode tags modified
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Ad Rotation Code LaPirata Script Requests 6 12-29-10 03:31 AM
HTML code file update on the webserver using CGI script sujata_ghosh Perl 31 07-06-06 03:06 AM
Explanation of Code... Please davidk19380 Perl 1 02-26-06 01:50 PM
Zip Code search range errors Merovingian PHP 2 02-09-06 03:33 PM


All times are GMT -5. The time now is 11:39 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.