1

How can I use img tag in php code?:

This is the code I have so far:

$message = $message."...<br /><a href=\"".$mybb->settings['bburl']."/".$announcement['threadlink']."\">".$lang->messagemore."</a>";

And I wish to use an image instead of ".$lang->messagemore." but I don't know how to use img tag in php :| I have tried googling but I only find some tag info from html but not php code.

<img src="/res/gif/bullet_info_sq.gif" alt="" />

But I wish to use that in php so I could use your help.

Thank you very much!

zessx
  • 68,042
  • 28
  • 135
  • 158
user1973003
  • 145
  • 2
  • 2
  • 9

7 Answers7

3

tl;dr

Replace: $lang->messagemore

With: <img src="/res/gif/bullet_info_sq.gif" alt="" />


When you replace your PHP variable with the img tag, the HTML must still remain within the quotes of the PHP string, and thus the actual quotes for your img tag must be escaped, just as you've done for your a tag. You may also opt to use single quotes, to avoid having to escape. This should result any one of the following equivalent code snippets (I've added whitespace for readability):

Double quotes (with escaping):

$message = $message . "...<br />
<a href=\"" . $mybb->settings['bburl'] . "/" . $announcement['threadlink'] . "\">
    <img src=\"/res/gif/bullet_info_sq.gif\" alt=\"\" />
</a>";

Single quotes for HTML attributes:

$message = $message . "...<br />
<a href='" . $mybb->settings['bburl'] . "/" . $announcement['threadlink'] . "'>
    <img src='/res/gif/bullet_info_sq.gif' alt='' />
</a>";

Single quotes for PHP string:

$message = $message . '...<br />
<a href="' . $mybb->settings['bburl'] . '/' . $announcement['threadlink'] . '">
    <img src="/res/gif/bullet_info_sq.gif" alt="" />
</a>';
Jon Newmuis
  • 25,722
  • 2
  • 45
  • 57
0

Just echo the HTML code ( in your case , the <img> tag ) in PHP , just like you did for <a> tag.

Raptor
  • 53,206
  • 45
  • 230
  • 366
0

You can use like this,

$message = $message."...<br /><a href=\"".$mybb->settings['bburl']."/".$announcement['threadlink']."\"><img src='/res/gif/bullet_info_sq.gif' alt='' /></a>";
Edwin Alex
  • 5,118
  • 4
  • 28
  • 50
0

use this:

$message = $message."...<br /><a href=\"".$mybb->settings['bburl']."/".$announcement['threadlink']."\">".'<img src="/res/gif/bullet_info_sq.gif" alt="" />'."</a>";
Engineer
  • 5,911
  • 4
  • 31
  • 58
0

Use this

$message = $message."...<br /><a href=\"".$mybb->settings['bburl']."/".$announcement['threadlink']."\"><img src=\"/res/gif/bullet_info_sq.gif\" alt=\"\" /></a>";
Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
0

It works like that:

$message = $message."...<br /><a href=\"".$mybb->settings['bburl']."/".$announcement['threadlink']."\">"."<img src='".$aImageURL."' alt="" /></a>";

Simply replace de img src with a PHP variable. ($aImageURL will be the URI of the image)

Take a look at the quotes (I put simply quotes in the src attribute, you can do that)

Alfonso Tienda
  • 3,442
  • 1
  • 19
  • 34
0

So simple, do not create mess with double quotes " PHP optimally used single quotes '. Use standard html within string!

echo ' <img src="php.gif" /> ';
Waqar Alamgir
  • 9,828
  • 4
  • 30
  • 36