1

My script writes content of < textarea > to text file:

&lt;!DOCTYPE html&gt;
&lt;html &lt;?php language_attributes(); ?&gt;&gt;
&lt;head&gt; etc

Is there anyway I can convert output to clean html so it looks like this:

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>

etc :)

$file = 'wp.txt';
$regex = '/<textarea name="example" id="newcontent">(.*?)<\/textarea>/s';
if ( preg_match($regex, $page, $list) )
echo $list[0];
else
print "Error";

$file = 'wp.txt';
file_put_contents($file, $list, FILE_APPEND | LOCK_EX);

Thanks!

2
  • If you don't like the answers could you give a better explanation. Aug 27, 2013 at 17:11
  • I'm not marking answers as not useful and I do not know who is doing it. Always appreciate any help :)
    – Kris
    Aug 27, 2013 at 17:16

3 Answers 3

1
html_entity_decode

http://php.net/manual/en/function.html-entity-decode.php

That should do the trick.

0

Use the method html_entity_decode....

    $file = 'wp.txt';
    $regex = '/<textarea name="example" id="newcontent">(.*?)<\/textarea>/s';
    if ( preg_match($regex, $page, $list) )
    echo html_entity_decode($list[0]);
    else
    print "Error";

    $file = 'wp.txt';
    file_put_contents($file, $list, FILE_APPEND | LOCK_EX);
1
  • I added echo html_entity_decode($list[0]); but the output in wp.txt is still full of &lt;!DOCTYPE html&gt; &lt;html :(
    – Kris
    Aug 27, 2013 at 17:18
0

You'll need the html_entitiy_decode function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.