PHP正则表达式取文本中间内容。

不太懂正则表达式,而且又是初学PHP,向各位高手或达人求段函数。示例代码如下(里面其他的内容还很多也不仅仅是一张图片):
<img src="http://127.0.0.1/test.jpg">
要求写个单独的函数参数为 html内容,返回 图片 路径 http://127.0.0.1/test.jpg 的数组。 谢谢!!!

比如说这样添加的计时器
Dim Timer1 As New Timer
要在合适的地方开始,比如窗体Load事件中,这样:
Timer1.Interval = 1000 '单位毫秒,1000毫秒=1秒
Timer1.Enabled = True '启用计时器

然后在代码窗口上方下拉列表里选择Timer1的Tick事件,自动添加代码:
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
End Sub

这是计时器触发的事件,每秒触发一次,在这里面输入循环判断是否有日程即可。提示:可以用Now对象获取当前的日期和时间。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-06-09

给你个例子吧。。

结果

本回答被提问者采纳
第2个回答  2014-06-09
这是n年前写的采集下载图片,剪切加水印的功能的类中的函数,有些图片是带参数的url,一般的都考虑到

你参考下
public function getRemoteImg($url,$imgWidth="",$imgHeight="",$cutPX=0, $cutPY=0,$waterImg="",$waterPX=0,$waterPY=0,$savePath=""){

if(empty($url)) return "";
if(empty($savePath)){
$savePath="../image/data/remoteImages/";
}
else
{
$savePath='../image/'.$savePath."/";

}

if(!file_exists($savePath)) mkdir($savePath,0777);
$savePath.=date('Y-m').'/';
if(!file_exists($savePath)) mkdir($savePath,0777);
$filename=$savePath.strrchr($url,"/");
$filename=str_replace('//','/',$filename);

$cutPX=(int)$cutPX;
$cutPY=(int)$cutPY;

/*读取图片 */
if(!stripos('lankii'.$url,'http://') && !stripos('lankii'.$url,'https://')){$url='http://'.$url;}
$imginfo = @getimagesize($url);
if(!$imginfo){return '';exit;}
$img_width = $imginfo[0];//取得图片的宽
$img_height = $imginfo[1];//取得图片的高

switch($imginfo[2])//取得图片的格式
{
case 1:$im = imagecreatefromgif($url);break;
case 2:$im = imagecreatefromjpeg($url);break;
case 3:$im = imagecreatefrompng($url);break;

}

if(empty($imgWidth)||empty($imgHeight)){
//如果截取了,新图片需要减去这部分,要不然会有黑色块
$new_img_width = $img_width;
$new_img_height =$img_height;

}else{
$new_img_width =(int)$imgWidth;
$new_img_height =(int)$imgHeight;
}

// 先建立一个 新的空白图片档
$newim = imagecreatetruecolor($new_img_width, $new_img_height);

// 输出图要从哪边开始x, y , 原始图要从哪边开始 x, y , 要输多大 x, y(resize) , 要抓多大 x, y
imagecopyresampled($newim, $im, 0, 0, $cutPX, $cutPY, $new_img_width, $new_img_height, $img_width-$cutPX, $img_height-$cutPY);

//水印代码
//设定混色模式
if(!empty($waterImg)){
imagealphablending($newim,true);
$waterinfo = getimagesize($waterImg);
$ww = $waterinfo[0];//取得图片的宽
$wh = $waterinfo[1];//取得图片的高

switch($waterinfo[2])//取得图片的格式
{
case 1:$water = imagecreatefromgif($waterImg);break;
case 2:$water = imagecreatefromjpeg($waterImg);break;
case 3:$water = imagecreatefrompng($waterImg);break;

}

//水印位置
if((int)$waterPX==0){
$waterPX=(($new_img_width-$ww)/2<=0)?0:($new_img_width-$ww)/2;
}
if((int)$waterPY==0){
$waterPY=(($new_img_height-$wh)/2<=0)?0:($new_img_height-$wh)/2;
}

//拼合水印
imagecopy ($newim,$water,$waterPX,$waterPY,0,0,$ww,$wh);
}

//保存图片
imagejpeg($newim,$filename,100);
// 资源回收
imagedestroy($newim);
imagedestroy($im);

return str_replace('../image/',HTTP_CATALOG . 'image/',$filename);

}

public function exchangeImgRemoteToLocal($content="",$homeUrl,$replaceArr=array(),$repTxtArr=array(),$download=true,$imgWidth="",$imgHeight="",$cutPX=0, $cutPY=0,$waterImg="",$waterPX=0,$waterPY=0){
if(empty($content)){return ''; exit;};

//if(!empty($waterImg) && !stripos($waterImg,'http://') && !stripos($waterImg,'https://')){$waterImg='http://'.$waterImg;}
//是否下载远程图片
if($download){
$s='/<img(.*?)src="(.*?)(?=")/i';
if(preg_match_all($s,$content,$array)>0){

foreach($array[2] as $IR){
$mir="";
$mir=$IR;
$mir=str_ireplace('../','',$mir);
if(!stripos('lankii'.$mir,'http://')&&!stripos('lankii'.$mir,'https://')){$mir=$homeUrl.'/'.$mir;}

$content= str_ireplace($IR,$this->getRemoteImg($mir,$imgWidth,$imgHeight,$cutPX, $cutPY,$waterImg,$waterPX,$waterPY),$content);
}
}
}

///替换符合规则的内容为指定内容
if(is_array($replaceArr)&&is_array($repTxtArr)){

if(count($replaceArr)>0&&count($replaceArr)==count($repTxtArr)){
if(trim(implode('',$replaceArr))!=''){
$content=preg_replace($replaceArr,$repTxtArr,$content);
}
}}

$content=preg_replace("/(<img)(.*?)src=(['\" ])?([0-9a-z\/\.:\?\#-]*)(['\" ])?(.*?)(\/>)/i",'[lankiiImgBegin] src="${4}" [lankiiImgEnd]',$content);
$content=strip_tags($content);
$content=str_ireplace("[lankiiImgBegin]","<img",$content);
$content=str_ireplace("[lankiiImgEnd]","/>",$content);

return $content;

}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网