IMG中的事件写为外部函数,比如onmouseover="mouseOverEvent()",里面不要包含*,?等特殊符号<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<script language="javascript">
var img = '<IMG onmousewheel=\"return imgzoom(this);\" src=\"/002.jpg\" border=0 />';
var   pattern   =   /<IMG.*?>/ig;
  var   myArray   =   pattern.exec(img);  
  var i =0 ;
  alert(myArray.length);
  for(i=0;i<myArray.length;i++) {
alert(myArray[i]);
  }
</script></BODY>
</HTML>

解决方案 »

  1.   

    <?php
    $str= <<<EOT
    <IMG onmousewheel=\"return imgzoom(this);\" onmouseover=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\" onclick=\"if(!this.resized) {return true;} else {window.open(\002.jpg\');}\" src=\"/002.jpg\" onload=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\" border=0>
    EOT;echo preg_replace('|(<img).*?(src=.*?)\s.*?(>)$|i','$1 $2 $3', $str);
    ?>output:<IMG src=\"/002.jpg\" >关键是你想得到什么?
      

  2.   

    这样并没有去掉里面的 onmouseover=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\"
    这个“>”大于号啊!
    现在是想去掉>号,提取出<img src="002.jpg">这个来
      

  3.   

    就是想得到 "图片的路径"  其他的都不需要dalfdasjfdsaf<IMG onmousewheel=\"return imgzoom(this);\" onmouseover=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor=\'hand\'; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\" onclick=\"if(!this.resized) {return true;} else {window.open(\002.jpg\');}\" src=\"/002.jpg\" onload=\"if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt=\'Click here to open new window\\nCTRL+Mouse wheel to zoom in/out\';}\" border=0>fdafdsafdsafd
    结果:
    dalfdasjfdsaf<IMG src=\"/002.jpg\" >fdafdsafdsafd