[eluser]bgougent[/eluser]
since some time I need to add alt tags to my image for a blind user.
When I use the default img() function in the html_helper I always get an error on the missing alt tag.
So I deceided to change the html_helper with my own html_helper file (application/helpers)
This is the code
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once( BASEPATH . '/helpers/html_helper'.EXT);
function img($src = '', $index_page = FALSE, $alt='')
{
if ( ! is_array($src) )
{
$src = array('src' => $src, 'alt' => $alt);
}
$img = '<img';
foreach ($src as $k=>$v)
{
if ($k == 'src' AND strpos($v, '://') === FALSE)
{
$CI =& get_instance();
if ($index_page === TRUE)
{
$img .= ' src="'.$CI->config->site_url($v).'" ';
}
else
{
$img .= ' src="'.$CI->config->slash_item('base_url').$v.'" ';
}
}
else
{
$img .= " $k=\"$v\" ";
}
}
$img .= '/>';
return $img;
}
I've added a third parameter 'alt'. If nothing is mentioned the alt is set - still empty. If definied I have a correct alt tag. Both are correct for the HTML validator
.