upsuperx
V2EX  ›  问与答

求 preg_match_all 正则表达式

  •  
  •   upsuperx · Nov 18, 2014 · 3049 views
    This topic created in 4218 days ago, the information mentioned may be changed or developed.
    求一条可用 PHP 中 preg_match_all 匹配 $html 中所有 js/css/img 链接的 正则表达式规则,也就是
    替换以下三条的一规则:

    preg_match_all('/<img[\s]+[^>]*src\s*=\s*([\"\']+)([^>]+?)(\1|>)/i', $html, $m);
    preg_match_all('/<link[\s]+[^>]*href\s*=\s*([\"\']+)([^>]+?)(\1|>)/i', $html, $m);
    preg_match_all('/<script[\s]+[^>]*src\s*=\s*([\"\']+)([^>]+?)(\1|>)/i', $html, $m);

    我用过 preg_match_all("/(href|src)=(\"|\')(.*?(?:\.(css|js|jpg|png|gif)))(.*)(\"|\')/i",$html, $m); 貌似不正常
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2987 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 03:16 · PVG 11:16 · LAX 20:16 · JFK 23:16
    ♥ Do have faith in what you're doing.