p1956
V2EX  ›  PHP

匹配前一半内容

  •  
  •   p1956 · Dec 9, 2022 · 2238 views
    This topic created in 1274 days ago, the information mentioned may be changed or developed.
    txt 有 600000 字节左右,只需要前面 300000 字节,任何字符都可能出现,包括回车、换行

    $txt = preg_replace('/(^[\s\S]{300000})[\s\S]*/','$1', $txt); 这段代码,字数小一点可以,加大后就不行,大概几万就不行了,300000 就更不行了
    2 replies    2022-12-09 14:22:56 +08:00
    eason1874
        1
    eason1874  
       Dec 9, 2022
    提取前 30 万字节,为啥要用正则,这应该用截断吧

    按字节截断用 substr ,按 UTF8 字符截断用 mb_substr
    p1956
        2
    p1956  
    OP
       Dec 9, 2022
    @eason1874 可以了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1047 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:11 · PVG 07:11 · LAX 16:11 · JFK 19:11
    ♥ Do have faith in what you're doing.