Putting an <img> tag in a text field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
adamyork
Forum Newbie
Posts: 4
Joined: Mon Nov 29, 2010 7:24 am

Putting an <img> tag in a text field

Post 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>";
}
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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="" />';
}
Post Reply