假如用<<<和>>>嵌套呢?

解决方案 »

  1.   

    function htmlsp($matches)
    {
    $text = htmlspecialchars(nl2br($matches[1])).$matches[2].htmlspecialchars(nl2br($matches[3]));
    return $text;
    }
    function replace()
    {
    $str = implode("",file("test.txt"));
    $p = "/(<!--.*)\[\[(.*?)\]\](.*-->)/i";
    $r = "$1[<span>[$2]</span>]$3";
    $str = preg_replace($p,$r,$str);
    $p = "/([^\[\]]*?)\[\[(.*?)\]\]([^\[\]]*?)/si";
    $text = preg_replace_callback($p,htmlsp,$str);
    print $text;
    }
    replace();
      

  2.   

    sandyuk(冰の沙隆) 您好,好久没来CSDN了,复帖迟了,请见谅
    我的TXT文本只是举了一个例子,并不是固定的格式。
    function htmlsp($matches)
    {
    $text = htmlspecialchars(nl2br($matches[1])).$matches[2].htmlspecialchars(nl2br($matches[3]));
    return $text;
    }函数里不用数组常数索引可以吗?