V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
FreeDog
V2EX  ›  PHP

PHP 正则求助,为什么 sublime 中替换正常,它就错了呢

  •  
  •   FreeDog · Oct 12, 2015 · 2048 views
    This topic created in 3853 days ago, the information mentioned may be changed or developed.

    我想把 :heart: 替换为 <i class="fa fa-heart"></i>

    在 sublime 中,我可以写 (:)([a-z]+)(:) 替换为 <i class="fa fa-\2"></i>

    可是在 PHP 中,我用

    preg_replace("(:)([a-z]+)(:)", "<i class=\"fa fa-$2\"></i>", $content);

    然后整个网页就乱掉了,好像匹配了好多不该匹配的东西。初学 PHP ,望指导。

    FreeDog
        1
    FreeDog  
    OP
       Oct 12, 2015
    自己解决了。两边加上 / 就好了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1643 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 16:16 · PVG 00:16 · LAX 09:16 · JFK 12:16
    ♥ Do have faith in what you're doing.