4

I have a string <div id="myid">...</div>

How would I change this into <div id="myid">...</div>

I have tried a few things but no luck any help?

Update

function get_page(){
  $file = 'file.php';
  $str = file_get_contents($file);
  $str = html_entity_decode($str);
  return $str;
}
$output = get_page();
echo $output;//don't work

FIX

function get_page(){
      $file = 'file.php';
      $str = file_get_contents($file);
      return $str;
    }
    $output = get_page();
    echo html_entity_decode($output);//works
0

5 Answers 5

18

The function for that is htmlspecialchars_decode().

Note that for the function to decode quotes, you need to specify the $quote_style parameter.

Sign up to request clarification or add additional context in comments.

18 Comments

@Val what result do you get? What code do you use? You are using it like this: $string = htmlspecialchars_decode($string);, right?
yes , and $str = htmlspecialchars_decode($str,ENT_NOQUOTES); still doesn't work. I save it into a file using fwrite, wen i try to output it to html it comes up as plain text not html element, if that helps
@Val your problem is most likely elsewhere. Try a echo $str; to see the output
hmm Your right... watch my update and try and help me where im going wrong.
the problem is there on the return $str
|
2

html_entity_decode is what you need: http://www.php.net/manual/en/function.html-entity-decode.php

Comments

1
$from = array('&lt;', '&gt;');
$to = array('<', '>');
$string = str_replace($from, $to, $string);

1 Comment

I could be here a year trying to figure out all the individual characters and secondly that could slow the page down,
1

use this it's better ...

<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// Allow <p> and <a>

echo strip_tags($text, '<p><a>');
?>

Comments

0
htmlspecialchars_decode($string)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.