FreeDog
V2EX  ›  PHP

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

  •  
  •   FreeDog · Oct 12, 2015 · 2385 views
    This topic created in 4042 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
    FreeDog
    OP
    Oct 12, 2015
    1
    自己解决了。两边加上 / 就好了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1728 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 00:00 · PVG 08:00 · LAX 16:00 · JFK 19:00
    ♥ Do have faith in what you're doing.