douzhi4056 2016-08-20 18:25
浏览 27

Bbcode“私人功能linkify”导致网站空白

When I was using this forum script on subdomain, it works very fine. But when I decided to move it to my main index (public_html) the site went blank.

At first I thought the error was from .htaccess, but I later discovered that the cause of the blank site is a particular code inside my bbcode.php.

Somebody should help me check what's wrong with this code:

private function linkify($value, $protocols = array('http', 'mail', 'https'), array $attributes = array(), $mode = 'normal')
    {
                // Link attributes
    $attr = '';
    foreach ($attributes as $key => $val) {
    $attr = ' ' . $key . '="' . htmlentities($val) . '"';
    }

    $links = array();

    // Extract existing links and tags
    $value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value);
     // Extract text links for each protocol
     foreach ((array)$protocols as $protocol) {
        switch ($protocol) {
            case 'http':
            case 'https': 
                $value = preg_replace_callback($mode != 'all' ? '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i' : '~([^\s<]+\.[^\s<]+)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { if ($match[1]) $protocol = $match[1]; $link = $match[2] ?: $match[3]; return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . '://' . $link . '">' . $link . '</a>') . '>'; }, $value);
                break;
            case 'mail': 
                $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', function ($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="mailto:' . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value);
                break;
            case 'twitter':
                $value = preg_replace_callback('~(?<!\w)[@#](\w++)~', function ($match) use (&$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="https://twitter.com/' . ($match[0][0] == '@' ? '' : 'search/%23') . $match[1] . '">' . $match[0] . '</a>') . '>'; }, $value); 
                break;
            default: $value = preg_replace_callback($mode != 'all' ? '~' . preg_quote($protocol, '~') . '://([^\s<]+?)(?<![\.,:])~i' : '~([^\s<]+)(?<![\.,:])~i', function ($match) use ($protocol, &$links, $attr) { return '<' . array_push($links, '<a' . $attr . ' href="' . $protocol . '://' . $match[1] . '">' . $match[1] . '</a>') . '>'; }, $value);
            break;
        }
    }

     // Insert all link
     return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value);
}

I need it to make topic message display

  • 写回答

1条回答 默认 最新

  • dongle2627 2016-11-09 15:15
    关注

    Just remove private.


    There is absolutely nothing wrong with your function—if there was, it would have broken the page that you copied it from as well. That just leaves your declaration:

    private function linkify($value, $protocols = array('http', 'mail', 'https'), array $attributes = array(), $mode = 'normal')
    

    Moreover, you said that adding the function made the page go blank. This is very important because it indicates a parsing error because if it was anything else it would have shown everything up to the first call.


    Now, what part of this declaration can create a parsing error in one place but not another?

    private function linkify($value, $protocols = array('http', 'mail', 'https'), array $attributes = array(), $mode = 'normal')
    

    My best guess where your error is would be the private in the declaration; in the original file, this was likely in a class body, making it completely legal, while in the main index, it was not in a class body, making it an illegally placed keyword.

    评论

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序