Hi,

I don't know what i have done but i want to recover code below. It is very long, i give you little part of it. Any idea how to recover it.

Thanks

<p><span class="caps">APRIL</span></p>

<p><span class="caps">SAT</span> 18<br>
<span class="caps">OPEN TUTORIAL </span>(10.00- 4.00)<br>
This day will include a session on Reflective Practice, Alternative Formats and Physical Skills. It is open to all SWs although the majority of participants are likely to be <span

Dani AI

Generated

The sample lines such as &amp;amp;lt;p&amp;amp;gt; show multiple layers of HTML-entity escaping: an original <p> became &lt;p&gt;, that became &amp;lt;p&amp;gt;, and so on. Recovery requires an entity-only decode applied repeatedly until the text stops changing. The fragment that ends with &amp;amp;lt;span also suggests the source may be truncated; a decoded result should be inspected for cut or missing tags.

Two practical options already mentioned in the thread are complementary: quick one-off fixes with an online decoder (as suggested) or an offline/scripted approach for long files and batch work (as outlined). For repeatable, safe recovery the preferred approach is a text-only decoder (not a DOM innerHTML decode) that loops until stable.

A concise Python 3 example that repeatedly decodes HTML entities:

# Python 3: decode repeated HTML-entity escaping until stable
import html

s = '...paste the encoded text here...'

while True:
    s2 = html.unescape(s)
    if s2 == s:
        break
    s = s2

print(s)

Notes and cautions: prefer libraries that only decode entities (Python html.unescape, Perl HTML::Entities, Node he) rather than inserting suspect content into the live DOM with innerHTML (which can create and execute script tags). After decoding, inspect the output in a plain-text editor, fix any truncated tags or mismatched quotes, and validate the markup before publishing. If embedding recovered HTML into JavaScript strings, avoid unescaped quotes by loading the content from a file or a textarea instead of hard-coding it into string literals.

Reference for the Python approach: Python html.unescape documentation.

Recommended Answers

All 6 Replies

Veledrom,

Here's what to do:

  1. Create a directory on your computer named "rescue".
  2. Copy and paste html file below (complete with its javascript) to a new text file and save as "index.html" in "rescue".
  3. Go and download - click the link "" about one third the way down the page. Your browser may invite you to save the file with some other name - change it back to "" before saving to your directory "rescue".
  4. Following my example below, paste all your encoded text into your file "index.html".
  5. On each line, add single quotes round the whole line then add the prefix txt[n] = and a final ; . (where n = 1, 2, 3, 4 etc.)
  6. Browse "index.html" in your browser.
  7. Highlight/copy the recovered markup from the textarea and paste to wherever it is needed.

The only problem I foresee is if any of the lines contain an unencoded single quote. If so, then track them all down and escape them by adding a backslash before each one. Should work.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Airshow :: HTML Recovery</title>
<!--  -->

<script src="php.packed.js"></script><!-- /*Download from  */
 -->
<script>
var txt = [];
/* ********************** */
txt[0] = '&amp;lt;p&amp;gt;&amp;lt;span class=&amp;quot;caps&amp;quot;&amp;gt;APRIL&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;';
txt[1] = '&amp;lt;p&amp;gt;&amp;lt;span class=&amp;quot;caps&amp;quot;&amp;gt;SAT&amp;lt;/span&amp;gt; 18&amp;lt;br&amp;gt;';
txt[2] = '&amp;lt;span class=&amp;quot;caps&amp;quot;&amp;gt;OPEN TUTORIAL &amp;lt;/span&amp;gt;(10.00- 4.00)&amp;lt;br&amp;gt;';
txt[3] = 'This day will include a session on Reflective Practice, Alternative Formats and Physical Skills. It is open to all SWs although the majority of participants are likely to be &amp;lt;span';
/* ********************** */

onload = function(){
	document.getElementById('txt').value = html_entity_decode(txt.join("\r\r"));
}
</script>
</head>
<body>
<textarea id="txt" style="width:500px; height:500px;"></textarea>
</body>
</html>

Good luck with it.

Airshow

copy the escape coded texted in the box and click the decode button

<p><span class="caps">APRIL</span></p>

<p><span class="caps">SAT</span> 18<br>
<span class="caps">OPEN TUTORIAL </span>(10.00- 4.00)<br>
This day will include a session on Reflective Practice, Alternative Formats and Physical Skills. It is open to all SWs although the majority of participants are likely to be <span <p><span class="caps">APRIL</span></p>

<p><span class="caps">SAT</span> 18<br>
<span class="caps">OPEN TUTORIAL </span>(10.00- 4.00)<br>
This day will include a session on Reflective Practice, Alternative Formats and Physical Skills. It is open to all SWs although the majority of participants are likely to be <span

Bob, I didn't think of looking for an online resource. That's much quicker.

Veledrom, unless you enjoy the challenge of doing it my way (and have the time), go with Bob's method.

Airshow

spent a lot of time repairing obfuscated and over-escaped codes where the original writer left the company, and they have no copy of the source

commented: Perfect help. Thanks almostbob +2

I knew there must be someone somewhere who made a career of it ;)

commented: Useful information. Thanks airhow +2

A very interesting side career,
some of the things hidden in obfuscated code when the author just got fired would . . . . . . . . .

glad it helped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.