Php 将标记图像显示为链接

Php 将标记图像显示为链接,php,markdown,Php,Markdown,我使用Michel Fortin's进行降价转换,但我希望将图像显示为链接而不是内联。因为任何人都可以从Imgur中插入5MB jpg并减慢页面速度 如何更改图像以链接到图像?覆盖的示例如下所示: class CustomMarkdown extends Markdown { function _doImages_reference_callback($matches) { $whole_match = $matches[1]; $alt_text

我使用Michel Fortin's进行降价转换,但我希望将图像显示为链接而不是内联。因为任何人都可以从Imgur中插入5MB jpg并减慢页面速度


如何更改图像以链接到图像?

覆盖的示例如下所示:

class CustomMarkdown extends Markdown
{
    function _doImages_reference_callback($matches) {
        $whole_match = $matches[1];
        $alt_text    = $matches[2];
        $link_id     = strtolower($matches[3]);

        if ($link_id == "") {
            $link_id = strtolower($alt_text); # for shortcut links like ![this][].
        }

        $alt_text = $this->encodeAttribute($alt_text);
        if (isset($this->urls[$link_id])) {
            $url = $this->encodeAttribute($this->urls[$link_id]);
            $result = "<a href=\"$url\">$alt_text</a>";
        } else {
            # If there's no such link ID, leave intact:
            $result = $whole_match;
        }

        return $result;
    }

    function _doImages_inline_callback($matches) {
        $whole_match    = $matches[1];
        $alt_text       = $matches[2];
        $url            = $matches[3] == '' ? $matches[4] : $matches[3];
        $title          =& $matches[7];

        $alt_text = $this->encodeAttribute($alt_text);
        $url = $this->encodeAttribute($url);
        return "<a href=\"$url\">$alt_text</a>";
    }
}
类CustomMarkdown扩展了Markdown
{
函数_doImages_reference_回调($matches){
$toull_match=$matches[1];
$alt_text=$matches[2];
$link_id=strtolower($matches[3]);
如果($link\u id==“”){
$link_id=strtolower($alt_text);#用于像![this][]这样的快捷链接。
}
$alt_text=$this->encodeAttribute($alt_text);
如果(设置($this->url[$link\u id])){
$url=$this->encodeAttribute($this->url[$link\u id]);
$result=“”;
}否则{
#如果没有此类链接ID,请保持原样:
$result=$whole_match;
}
返回$result;
}
函数_doImages_inline_回调($matches){
$toull_match=$matches[1];
$alt_text=$matches[2];
$url=$matches[3]=''?$matches[4]:$matches[3];
$title=&$matches[7];
$alt_text=$this->encodeAttribute($alt_text);
$url=$this->encodeAttribute($url);
返回“”;
}
}

演示:

您应该看看。这是一个较新的,而且我相信,更容易扩展标记的实现。

我尝试过正则表达式、好的旧stru_ireplace和substr。但图像可以替换文本和标题,或仅替换标题等。这并不是唯一的条件。而且stru_ireplace也改变了代码块中的img文本。我也不好意思承认,但我甚至尝试用XML工具更改结果HTML DOM,但我放弃了,因为这不是一个可行的选择。在转换后,你没有尝试做你的事情,而是考虑寻找降价的来源并搜索idunno方法吗?我很抱歉。我不知道我怎么会忘记简单的OO原则:)我想我可以重写_doImages_reference_回调函数并实现我想要的:)谢谢:)