I'm using following code to display an image with CodeIgniter framework.
<?php echo img('sample/logo.png'); ?>
And this is producing following output::
<img alt="" src="http://localhost:8080/test/css/sample/logo.png">
Why it does not closes the tag with />
Also, how can i specify the alt
text when i echo image?
thanks
According to user guide, it should end with />. I tried it out, and it works.
If you want a shorter tag, use this:
<?php echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); ?>
Sometimes if you view source using certain browsers (firefox, chrome), it omits the /> tag. Try view source using a notepad or something, it should display proper /> tag.
$image_properties = array(
'src' => 'sample/logo.png',
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
'class' => 'post_images',
'width' => '200',
'height' => '200',
'title' => 'That was quite a night',
'rel' => 'lightbox',
);
img($image_properties);
// <img src="http://site.com/index.php/sample/logo.png" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
reference : http://codeigniter.com/user_guide/helpers/html_helper.html#img
Dont echo an image like that, do it like this:
echo "<img src='sample/logo.png' alt='my company name' title='my company logo' border='0' />";
Remeber the location you have there is relative, you should try to stick to absolute paths were possible eg: "/test/css/sample/logo.png" to avoid confusion.
(sorry, missed the bit where you said you were using a framework).