问题描述:

html form

<html><body>

<form action="process.php" method="post">

Headline:<input type="text" name="head"><br>

Content:<Textarea rows="4" cols="50" name="cont"></textarea>

</form>

</html>

my table structure

two fields are headline,content.

Filling the form:

Headline- "this is crazy"

Content- "here i want to put image like this..

<img src="$image" /> "

Process.php

in this i get Headline and content from form in two php variable

$headline=$_POST['head'];

$content=$_POST['cont'];

here i have one variable $image which contains address of image like: $image contains "img\thumb\2.jpg"

i've to insert $headline and $content into table.

problem

whenever i insert headline and content into table... headline goes fine into table..but in content it shows: "here i want to put image like this..

&lt;img src=&quot;$image&quot; /&gt; "

why $image actual value is not getting parsed?

any solution?

网友答案:

You're not actually "in PHP" when you're attempting to output it.

In other words, you have to open a PHP section to echo the variable:

<?php echo $image; ?>

or, with your image tag:

<img src="<?php echo $image; ?>" />
网友答案:

It's because when you write $image into HTML textarea, it's treated as a string not as variable.

So, you should write the full image URL to your database, something like img\thumb\2.jpg and then read it to the browser.

网友答案:

Use html_entity_decode Convert all HTML entities to their applicable characters

html_entity_decode($content);

Example

$b = html_entity_decode("I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now");

echo $b; // I'll "walk" the <b>dog</b> now
网友答案:

See when you are trying to input special characters like <, >, & etc. they are converted into their HTML formats like < is converted into &lt;, similarly > is converted into &gt;. Thats why when you are trying to insert < or > symbol in database it is inserting it like &lt; and &gt;. You shouldn't use them like this. But if you really need them you can replace &lt; with < and &gt; with > just before Insert query.

$qry = "INSERT INTO TEST (HEAD, CONTENT) VALUES (" . $head . ", " . $content . ")";
$qry = str_replace("&lt;", "<", $qry);
$qry = str_replace("&gt;", ">", $qry);

and then you can use $qry for insertion.

相关阅读:
Top