开发者

PHP MySql display returned content without html tags being stripped

I have a column in SQL 'Text' datatype and inside I have content within html tag, eg

somecontent:

  • one
  • two
... I want the mysql query to echo out the databases contents without stripping the html tags (its possible this is done by php for security reasons or?) so that the html code will render if you get me? At the moment it just lumps out a paragraph which looks a开发者_StackOverflowweful! It should be noted security is not much of a concern as this is a project and not going to be exposed publicly

Cheers folks

Nick


MySQL wouldn't strip tags from text - it couldn't care less what the text is. PHP also wouldn't strip tags, unless somewhere in your code you do a strip_tags() or equivalent.

If you want to force the browser to display the tags in the retrieved data, you can run the string through [htmlspecialchars()][1], which converts html metacharacters (<, >, ", &, etc...) to their character entity equivalents (&lt;, &gt;, etc...).

Or you can force the entire page to be rendered as plain text by doing

header('Content-type: text/plain');


Database content isn't stripped by PHP unless you explicitly tell it to. Are you sure your tags haven't been stripped before they were inserted?

Alternatively try stripslashes();


Use htmlspecialchars_decode() function. Its works fine for me...

Use guideline

Your Text with code

<?php

$text = " 
<html>
<head>
    <title>Page Title</title>
</head>
<body>
     Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.
</body>
</html> ";

OR

$text = $row['columnname'];  // Here define your database table column name.

echo htmlspecialchars_decode($text);  

?>

Output:

Reference site about Lorem Ipsum, giving information on its origins, as well as a random Lipsum generator.


this works for me:

Ex:

<?=htmlspecialchars_decode(htmlspecialchars('I <b>love</b> you'))?>

Your browser will output: I love you


Use bellow snippet:

echo(strip_tags($your_string));

copied.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜