FreeDog
V2EX  ›  PHP

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

  •  
  •   FreeDog · Oct 12, 2015 · 2135 views
    This topic created in 3914 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   ·   5380 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 06:01 · PVG 14:01 · LAX 23:01 · JFK 02:01
    ♥ Do have faith in what you're doing.