你打开那些下载的ubb论坛什么的,就有这方面的代码。
看我的:bbs.soulsky.net.。其中的wdbcode.lib就是。
你要的代码:preg_replace("/\[img\](\r\n|\r|\n)*((http|https):\/\/([^;<>\*\(\)\"]+)|[a-z0-9\/\\\._\- =?]+)\[\/img\]/isU","<A HREF=\"\\2\" TARGET=_blank title=新窗口打开图片><img src=\"\\2\" border=0 onload=\"javascript:if(this.width>screen.width-350)this.width=screen.width-350\"></a>",$post)
看我的:bbs.soulsky.net.。其中的wdbcode.lib就是。
你要的代码:preg_replace("/\[img\](\r\n|\r|\n)*((http|https):\/\/([^;<>\*\(\)\"]+)|[a-z0-9\/\\\._\- =?]+)\[\/img\]/isU","<A HREF=\"\\2\" TARGET=_blank title=新窗口打开图片><img src=\"\\2\" border=0 onload=\"javascript:if(this.width>screen.width-350)this.width=screen.width-350\"></a>",$post)
<!--
var str = "《IMG height=30 src=\"face16.gif\" width=30 align=right border=3》";
var re = /^(《)(IMG.[^》]*)(》)$/g;
alert(str.replace(re,"<$2>"));
//-->
</Script>
<?php
$str = '<IMG height=30 src="face16.gif" width=30 align=right border=3>';
$reg = array("/<img.+width=([\"\']?)(.+)\\1(\s+|\s*>)/iU",
"/<img.+height=([\"\']?)(.+)\\1(\s+|\s*>)/iU",
"/<img.+align=([\"\']?)(.+)\\1(\s+|\s*>)/iU",
"/<img.+border=([\"\']?)(.+)\\1(\s+|\s*>)/iU");
$ubbstr = "[img=";
for ($i=0;$i<count($reg);$i++)
{
preg_match($reg[$i],$str,$input);
$ubbstr .= $input[2].",";
}
$ubbstr = rtrim($ubbstr,",");
echo $ubbstr;
?>