yoyo
yoyo

Reputation: 157

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:

... 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 aweful! 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

Upvotes: 1

Views: 4150

Answers (5)

Baseer Ebadi
Baseer Ebadi

Reputation: 173

Use bellow snippet:

echo(strip_tags($your_string));

copied.

Upvotes: 0

free2idol1
free2idol1

Reputation: 320

this works for me:

Ex:

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

Your browser will output: I love you

Upvotes: 0

Obaidul Haque
Obaidul Haque

Reputation: 960

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.

Upvotes: 0

Marc B
Marc B

Reputation: 360872

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

Upvotes: 1

Andre Backlund
Andre Backlund

Reputation: 6953

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();

Upvotes: 1

Related Questions