doudu8291 2011-07-19 09:19
浏览 38

用正则表达式替换图像

I want to find and do some operations on this string:

<img src="images/video.png" border="0" alt="60" />
  1. Find every occurence in context
  2. Retrieve the alt attribute (in this case 60) and work with this number
  3. Replace the whole image

I've been playing around with regular expressions but it obviously doesn't work yet:

    if (preg_match_all('<img src="images/video.png" border="0" alt="[^"]*">', $content, $regs)) {
    for($i=0;$i<count($regs[0]);$i++){

        echo $regs[0][$i] . "<br>";
        $id = preg_replace('alt="[^"]*"', "$1", $regs[0][$i]);
        echo "The id: " . $id . "<br>";

    }
}
  • 写回答

6条回答 默认 最新

  • doumo3903 2011-07-19 09:22
    关注

    You should use DOM to parse XML/HTML...

    评论

报告相同问题?

悬赏问题

  • ¥15 html5+css有人可以帮吗?
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?