Val
Val

Reputation: 17542

php string convert to html

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

Upvotes: 4

Views: 76056

Answers (5)

HAMMOU REDOUANE
HAMMOU REDOUANE

Reputation: 29

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>');
?>

Upvotes: 1

PeeHaa
PeeHaa

Reputation: 72739

htmlspecialchars_decode($string)

Upvotes: 0

Yeroon
Yeroon

Reputation: 3243

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

Upvotes: 2

Napas
Napas

Reputation: 2811

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

Upvotes: 1

Pekka
Pekka

Reputation: 449843

The function for that is htmlspecialchars_decode().

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

Upvotes: 18

Related Questions