Usage: {html_anchor href='' text='' attrs='' secure=false}
Required: href and text

@return string
162648
public function html_anchor($params) {
        if (!isset($params['href'])) {
            throw new \UnexpectedValueException("The href parameter is required.");
        }
        if (!isset($params['text'])) {
            throw new \UnexpectedValueException("The text parameter is required.");
        }
        $attrs = isset($params['folder']) ? $params['folder'] : array();
        $secure = isset($params['secure']) ? $params['secure'] : null;
        return Html::anchor($params['file'], $params['text'], $attrs, $secure);
    }
893467
function toHTML()
    {

        // get private attributes
        $attributes = $this->get_attributes('label');

        // if access key needs to be showed
        if (preg_match('/(?<!\\\)\$(.{1})/', $attributes['label'], $matches) > 0) {

            // set the requested accesskey
            $this->set_attributes(array('accesskey' => strtolower($matches[1])));

            // make the accesskey visible
            $attributes['label'] = preg_replace('/\$(.{1})/', '<span class="underline">$1</span>', $attributes['label']);

        }

        return '<label ' . $this->_render_attributes() . '>' . preg_replace('/\\\\\$/', '$', $attributes['label']) . '</label>';

    }
955189
public function autoLink($text)
    {
        $rexProtocol = '(https?://)?';
        $rexDomain = '((?:[-a-zA-Z0-9]{1,63}\.)+[-a-zA-Z0-9]{2,63}|(?:[0-9]{1,3}\.){3}[0-9]{1,3})';
        $rexPort = '(:[0-9]{1,5})?';
        $rexPath = '(/[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]*?)?';
        $rexQuery = '(\?[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';
        $rexFragment = '(#[!$-/0-9:;=@_\':;!a-zA-Z\x7f-\xff]+?)?';

        $text = preg_replace_callback(
            "&\\b$rexProtocol$rexDomain$rexPort$rexPath$rexQuery$rexFragment(?=[?.!,;:\"]?(\s|$))&",
            function ($match) {
                // Prepend http:// if no protocol specified
                $completeUrl = $match[1] ? $match[0] : "http://{$match[0]}";

                return '<a href="'.$completeUrl.'" target="_blank">'
                    .$match[2].$match[3].$match[4].'</a>';
            },
            htmlspecialchars($text)
        );

        return $text;
    }
697292
protected function getScriptText()
    {
        $scriptText = "";
        foreach ($this->imageUrls as $imageUrl) {
            $escapedImageUrl = Builder::escapeText($imageUrl);
            $scriptText      .= "
PreloadImage({$escapedImageUrl});";
        }
        return $scriptText;
    }
1015942
def _link_to(self, page, text=None, title=None, _class="", id="", alt="", **kwargs):
        
        anchor = ""
        if "#" in page:
            page, anchor = page.split("#")
            anchor = "#" + anchor
        meta = self._get_page_meta(page)
        return "<a href='{url}' class='{_class}' id='{id}'  title=\"{title}\">{text}</a>".format(
            url=meta.get("url", "/") + anchor,
            text=text or meta.get("title") or title,
            title=title or "",
            _class=_class,
            id=id
        )
420077
public function getHtml(): string
  {
    $html = $this->prefix;
    $html .= Html::generateTag('span', $this->attributes);

    if (is_array($this->options))
    {
      foreach ($this->options as $option)
      {
        $inputAttributes = $this->inputAttributes($option);
        $labelAttributes = $this->labelAttributes($option);

        $labelAttributes['for'] = $inputAttributes['id'];

        // Get the (database) key of the option.
        $key  = $option[$this->keyKey];

        // If an obfuscator is installed compute the obfuscated code of the (database) ID.
        $code = ($this->optionsObfuscator) ? $this->optionsObfuscator->encode(Cast::toOptInt($key)) : $key;

        $inputAttributes['name']    = ($this->submitName!=='') ? $this->submitName.'['.$code.']' : $code;
        $inputAttributes['checked'] = ($this->checkedKey!==null && !empty($option[$this->checkedKey]));

        $html .= Html::generateVoidElement('input', $inputAttributes);

        $html .= $this->labelPrefix;
        $html .= Html::generateElement('label',
                                       $labelAttributes,
                                       Cast::toOptString($option[$this->labelKey]),
                                       $this->labelIsHtml);
        $html .= $this->labelPostfix;
      }
    }

    $html .= '</span>';
    $html .= $this->postfix;

    return $html;
  }
723886
public function getHtml()
    {
        if (!$this->exists()) {
            return '';
        }
        switch ($this->type) {
            case 'datetime':
                $html = '<abbr title="'.$this->content->format('c').'">'
                    .(class_exists('WebSyndication\Helper') ?
                        \WebSyndication\Helper::getLocalizedDateString($this->content) : $this->content->format('D j m Y H:i:s')
                    ).'</abbr>';
                break;
            case 'time':
                $html = $this->content->format('H:i:s');
                break;
            case 'email':
                $html = '<a href="mailto:'.$this->content.'" title="Contact this email">'.$this->content.'</a>';
                break;
            case 'url':
                $html = '<a href="'.$this->content.'" title="See online">'.$this->content.'</a>';
                break;
            case 'text':
                $html = $this->xml_value;
                break;
            case 'lang':
                $html = '<abbr title="ISO : '.$this->xml_value.'">'.$this->content.'</abbr>';
                break;
            case 'list':
                $html = '';
                foreach ($this->content as $_ctt) {
                    $html .= (strlen($html) ? ', ' : '').$_ctt->content;
                }
                break;
            default:
                $html = $this->content;
                break;
        }
        return $html;
    }
1372840
protected function escapeAttribute(): string
    {
        $value = $this->validateEncoding();
        $value = strip_tags($value);

        return htmlspecialchars($value, ENT_QUOTES);
    }
309698
public static function urlLink($text, $url, $parameters = [], $secure = null)
    {
        return $this->createElement('a')->text($text)
            ->href(url($url, $parameters, $secure));
    }
1130923
public function getAnchor()
    {
        if ($this->anchor !== null) {
            return $this->anchor;
        }

        $anchorTitle = '';

        if (!$this->config()->disable_pretty_anchor_name) {
            if ($this->hasMethod('getAnchorTitle')) {
                $anchorTitle = $this->getAnchorTitle();
            } elseif ($this->config()->enable_title_in_template) {
                $anchorTitle = $this->getField('Title');
            }
        }

        if (!$anchorTitle) {
            $anchorTitle = 'e'.$this->ID;
        }

        $filter = URLSegmentFilter::create();
        $titleAsURL = $filter->filter($anchorTitle);

        // Ensure that this anchor name isn't already in use
        // ie. If two elemental blocks have the same title, it'll append '-2', '-3'
        $result = $titleAsURL;
        $count = 1;
        while (isset(self::$used_anchors[$result]) && self::$used_anchors[$result] !== $this->ID) {
            ++$count;
            $result = $titleAsURL . '-' . $count;
        }
        self::$used_anchors[$result] = $this->ID;
        return $this->anchor = $result;
    }
231618
protected function getAttributesAsHtml()
	{
		$htmlAttrs = '';
		
		foreach($this->attributes as $attrName => $attrValue) {
			$htmlAttrs .= ' ' . $attrName . (($attrValue === null || strlen($attrValue) === 0)?null:'="' . $attrValue . '"');
		}
		
		return $htmlAttrs;
	}
1008943
protected function getRegexp()
	{
		$anchor = RegexpBuilder::fromList($this->configurator->urlConfig->getAllowedSchemes()) . '://';
		if ($this->matchWww)
		{
			$anchor = '(?:' . $anchor . '|www\\.)';
		}

		$regexp = '#\\b' . $anchor . '\\S(?>[^\\s()\\[\\]'
		        . '\\x{FF01}-\\x{FF0F}\\x{FF1A}-\\x{FF20}\\x{FF3B}-\\x{FF40}\\x{FF5B}-\\x{FF65}'
		        . ']|\\([^\\s()]*\\)|\\[\\w*\\])++#Siu';

		return $regexp;
	}
739996
protected function validateUrl()
    {
        $this->url->stripQueryString();
        $this->url->stripLastSlash();
        $this->url->stripWWW();
        $this->url->convertToHttps();

        return (preg_match('~theysaidso\.com/(?:i|quote)/(?:[^/]+)$~i', $this->url));
    }
159804
public static function a($path, $text = NULL, $base_path = true, array $attrs = array())
    {
        if($base_path)
            $path = self::getBaseSite() . ltrim($path, '/');
        $attrs['href'] = $path;
            
        return self::tag('a', $text, false, false, $attrs);
    }
1187906
public function render(): string
    {
        $this->tags();

        if ($this->isLink === true) {
            $this->html .= "<a href=\"{$this->link}\">";
        }

        $element_attributes = '';
        foreach ($this->element_attributes as $attribute => $value) {
            if ($attribute == "color") {
                $element_attributes .= "style=\"{$attribute}: $value\"";
            } else {
                $element_attributes .= "{$attribute}=\"{$value}\" ";
            }
        }

        foreach ($this->tags as $i => $tag) {
            if ($i === 0 && strlen($element_attributes) > 0) {
                $this->html .= "<{$tag} " . rtrim($element_attributes) . '>';
            } else {
                $this->html .= "<{$tag}>";
            }
        }

        $this->html .= $this->escape($this->insert);

        foreach (array_reverse($this->tags) as $tag) {
            $this->html .= "</{$tag}>";
        }

        if ($this->isLink === true) {
            $this->html .= '</a>';
        }

        return $this->html;
    }
1091088
public function Link()
    {
        $link = '';
        switch ($this->type) {
            case 'Internal' :
                if ($this->internal && ($page = SiteTree::get()->byID($this->internal))) {
                    $link = $page->Link();
                }
                break;
            case 'External' :
                $link = $this->external;
                break;
            case 'Email' :
                $link = $this->email ? 'mailto:' . $this->email : '';
                break;
            case 'File' :
                if ($this->file) {
                    $link = File::get()->byID($this->file)->Filename;
                }
                break;
            case 'DataObject':
                if ($do = $this->getDO()) {
                    $link = $do->Link();
                }
                break;
        }

        if ($this->extra) {
            //added a query string, but no ? to start it
            if (strpos($this->extra, '=' !== false && strpos($this->extra, '?' === false))) {
                $link .= '?';
            }

            $link .= $this->extra;
        }

        if ($this->anchor) {
            $link .= '#' . $this->anchor;
        }

        return $link;
    }
355134
public function resolveLinkAndTitle()
    {
        $regrex = "/(?:href=['\"](?<link>.+)['\"])?(?:>(?<title>.+)<)/";

        preg_match($regrex, $this->markup, $matches);

        $this->link = $matches['link'];
        $this->title = $matches['title'];
    }