Skip to content

Instantly share code, notes, and snippets.

@ruthlessfish
Created August 24, 2011 20:57
Show Gist options
  • Save ruthlessfish/1169209 to your computer and use it in GitHub Desktop.
Save ruthlessfish/1169209 to your computer and use it in GitHub Desktop.
Url helper function overrides
<?php defined('BASEPATH') or exit('No direct script access allowed');
/**
* Anchor Link
*
* Creates an anchor based on the local URL.
*
* @access public
* @param string the URL
* @param string the link title
* @param mixed any attributes
* @return string
*/
if ( ! function_exists('anchor'))
{
function anchor($uri = '', $title = '', $attributes = '', $relative = FALSE)
{
$title = (string) $title;
if ( $relative === TRUE)
{
$site_url = is_array($uri) ? implode('/', $uri) : $uri;
}
elseif ( ! is_array($uri))
{
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else
{
$site_url = site_url($uri);
}
if ($title == '')
{
$title = $site_url;
}
if ($attributes != '')
{
$attributes = _parse_attributes($attributes);
}
return '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment