选择语言 :

 Core_HTML::anchor

Create HTML link anchors. Note that the title is not escaped, to allow HTML elements within links (images, etc).

echo HTML::anchor('/user/profile', 'My Profile');
string Core_HTML::anchor( string $uri [, string $title = null , array $attributes = null , string $protocol = null ] )
uses
URL::base
URL::site
HTML::attributes

参数列表

参数 类型 描述 默认值
$uri string URL or URI string
$title string Link text null
$attributes array HTML anchor attributes null
$protocol string Use a specific protocol null
返回值
  • string
File: ./core/classes/html.class.php
public static function anchor($uri, $title = null, array $attributes = null, $protocol = null)
{
    if ($title === null)
    {
        // Use the URI as the title
        $title = $uri;
    }
    if ($uri === '')
    {
        // Only use the base URL
        $uri = Core::url()->base(false, $protocol);
    }
    else
    {
        if (strpos($uri, '://') !== false)
        {
            if (HTML::$windowed_urls === true && empty($attributes['target']))
            {
                // Make the link open in a new window
                $attributes['target'] = '_blank';
            }
        }
        elseif ($uri[0] !== '#' && $uri[0] != '/')
        {
            // Make the URI absolute for non-id anchors
            $uri = Core::url($uri, $protocol);
        }
    }
    // Add the sanitized link to the attributes
    $attributes['href'] = $uri;
    return '<a' . HTML::attributes($attributes) . '>' . $title . '</a>';
}