Page 1 of 1

Putting an <img> tag in a text field

Posted: Mon Nov 29, 2010 7:27 am
by adamyork
Ok, apologies if this is really basic knowledge - but I am just starting out with PHP.

What I'm trying to do is save some text (that contains "<img>") into a text field.

Putting it all in inverted commas doesn't seem to work properly, so is there any way of doing this?

My code is:


if(!$_POST['newsimg'])
{
$_POST['newsimg'] = "<img src="www.shotguneffect.com/news_feed/images/ ... efault.jpg" alt="" /img>";
}

Re: Putting an <img> tag in a text field

Posted: Mon Nov 29, 2010 7:30 am
by Celauran
You need to escape the inner quotation marks.

Code: Select all

if(!$_POST['newsimg'])
{
$_POST['newsimg'] = "<img src=\"www.shotguneffect.com/news_feed/images/article_default.jpg\" alt=\"\" />";
}
Or you could mix single and double quotes.

Code: Select all

if(!$_POST['newsimg'])
{
$_POST['newsimg'] = '<img src="www.shotguneffect.com/news_feed/images/article_default.jpg" alt="" />';
}